Hi
I am trying to create a SQL Server DSN using code. I want to create the DSN for a specified server, database, username and password. I can create a DSN using SQLConfigDataSource without specifying a username and password however when I do specify a username and password the SQLConfigDataSource function fails. I need to create the DSN for a third party product and want to avoid using trusted connections.
Please see the following code example which is based on MSDN article Q171146 HOWTO: Create and Remove a DSN in Visual Basic
I am trying to connect to a SQL Server version 7.0 using VB6 Enterprise and the version of my odbccp32.dll is 3.520.6019.0
Any help would be really appreciated
Thanks
David
I am trying to create a SQL Server DSN using code. I want to create the DSN for a specified server, database, username and password. I can create a DSN using SQLConfigDataSource without specifying a username and password however when I do specify a username and password the SQLConfigDataSource function fails. I need to create the DSN for a third party product and want to avoid using trusted connections.
Please see the following code example which is based on MSDN article Q171146 HOWTO: Create and Remove a DSN in Visual Basic
Code:
Option Explicit
'Constant Declaration
Private Const ODBC_ADD_DSN = 4 ' Add system data source
Private Const vbAPINull As Long = 0& ' NULL Pointer
'Function Declare
Private Declare Function SQLConfigDataSource Lib "odbccp32.dll" _
(ByVal hwndParent As Long, ByVal fRequest As Long, _
ByVal lpszDriver As String, ByVal lpszAttributes As String) _
As Long
Private Sub Command1_Click()
Dim intRet As Long
Dim strDriver As String
Dim strAttributes As String
'Set the driver to SQL Server
strDriver = "SQL Server"
'Set the attributes delimited by null.
strAttributes = "SERVER=SERVER1" & Chr$(0)
strAttributes = strAttributes & "DSN=DSNTest" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=Test DataSource" & Chr$(0)
strAttributes = strAttributes & "DATABASE=pubs" & Chr$(0)
'Uncommenting the following causes SQLConfigDataSource to fail
'strAttributes = strAttributes & "uid=sa" & Chr$(0)
'strAttributes = strAttributes & "pwd=password" & Chr$(0)
intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, strDriver, strAttributes)
If intRet Then
MsgBox "DSN Created"
Else
MsgBox "Create Failed"
End If
End Sub
Any help would be really appreciated
Thanks
David