From: mat on
Can anyone spot what's wrong with the code below which attempts to
create a system dsn using sql server authentication? The login id and
password are good for sure so is the db name and server name.

Private Declare Function SQLConfigDataSource Lib "odbccp32.dll" _
(ByVal hwndParent As Long, _
ByVal fRequest As Integer, _
ByVal lpszDriver As String, _
ByVal lpszAttributes As String) As Long

public CreateDSN()

dim lngResult as long
' skip stuff
lngResult = SQLConfigDataSource(0, _
ODBC_ADD_SYS_DSN, _
"SQL Native Client", _
"DSN=mydsn" & & Chr(0) & _
"Server=" & strServerName & Chr(0) & _
"Database=mydb" & Chr(0) & _
"Trusted_Connection=No" & Chr(0) & _
"Uid=sql_login" & Chr(0) & _
"Pwd=secret" & Chr(0) & Chr(0))
'lngResult is always 0.
End function

The system dsn 'mydsn' does not exist. Windows xp, Access 2003, sql
server 2005.
From: mat on
Found a good way to create a system dsn at

http://support.microsoft.com/kb/184608

Still curious to know why the code below failed, if anyone can spot it.

In article <MPG.2600ab7035c6e0669897bb(a)msnews.microsoft.com>,
mat(a)notarealdotcom.adr says...
> Can anyone spot what's wrong with the code below which attempts to
> create a system dsn using sql server authentication? The login id and
> password are good for sure so is the db name and server name.
>
> Private Declare Function SQLConfigDataSource Lib "odbccp32.dll" _
> (ByVal hwndParent As Long, _
> ByVal fRequest As Integer, _
> ByVal lpszDriver As String, _
> ByVal lpszAttributes As String) As Long
>
> public CreateDSN()
>
> dim lngResult as long
> ' skip stuff
> lngResult = SQLConfigDataSource(0, _
> ODBC_ADD_SYS_DSN, _
> "SQL Native Client", _
> "DSN=mydsn" & & Chr(0) & _
> "Server=" & strServerName & Chr(0) & _
> "Database=mydb" & Chr(0) & _
> "Trusted_Connection=No" & Chr(0) & _
> "Uid=sql_login" & Chr(0) & _
> "Pwd=secret" & Chr(0) & Chr(0))
> 'lngResult is always 0.
> End function
>
> The system dsn 'mydsn' does not exist. Windows xp, Access 2003, sql
> server 2005.
>