MS SQL 2008 R2 with ODBC

I have a small application based on WINAPI from which I need to connect to MS SQL Server 2008 R2 through ODBC.
I had created the needed DSN and configured it. Its testing was successful.
However, when it came to my code, things are not working. I am calling SQLConnect function and getting the below error:
1
2
3
4
SQL_ERROR:
"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
SQLSTATE:
"IM002"

Please your help is highly needed.

Regards,
Any update on the above problem?
It looks to me like you had a problem calling the function, mislabeled your DSN or something like that. Without seeing any code I don't think anyone here can help that much.

A likely possibility (again without seeing any code I don't really know) is that you simply messed up one of the parameters in the SQLConnect function. The function as I'm sure you know is supposed to be:

1
2
3
4
5
6
7
8
SQLConnect(SQLRETURN SQLConnect(
     SQLHDBC        ConnectionHandle,
     SQLCHAR *      ServerName,
     SQLSMALLINT    NameLength1,
     SQLCHAR *      UserName,
     SQLSMALLINT    NameLength2,
     SQLCHAR *      Authentication,
     SQLSMALLINT    NameLength3);


But if you put in for example: Servername
instead of: SERVERNAME
It would give you trouble due to case sensitivity. I'm not going to list other possible mistakes in calling the function but start there because if your DSN is functioning normally in every regard except for this function call then I would have to assume the problem is in the function call.

In this case I would refer to the MSDN...
http://msdn.microsoft.com/en-us/library/ms711810(v=vs.85).aspx

Good Luck,
Sean
Last edited on
slambert: thx for your update.
I fixed the problem. It took me several hours. The problem was in the data conversion from char * to SQLWCHAR *.
I initiated the values to char * variables, then I converted those variable to wchar_t * that is equivalent to SQLWCHAR*.

Anyway, thanks again for you since you were the only who replied ;)

Regards,
That makes a lot of sense, I figured it was something like that. Glad you got it.
Topic archived. No new replies allowed.