slgal
asked on
Create SQL Server DSN
Hi,
I wanna create a SQL Server DSN programatically using WinAPI, anybody can give me sample coding?
Thx
I wanna create a SQL Server DSN programatically using WinAPI, anybody can give me sample coding?
Thx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, You can use this API also like this
#If WIN32 Then
Dim intRet As Long
#Else
Dim intRet As Integer
#End If
Dim strDriver As String
Dim strAttributes As String
'Set the driver to SQL Server because it is most common.
strDriver = "SQL Server"
'Set the attributes delimited by null.
'See driver documentation for a complete
'list of supported attributes.
strAttributes = "SERVER=SomeServer" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0)
strAttributes = strAttributes & "DSN=DSN_TEMP" & Chr$(0)
strAttributes = strAttributes & "DATABASE=pubs" & Chr$(0)
strAttributes = strAttributes & "UID=sa" & Chr$(0)
strAttributes = strAttributes & "PWD=" & Chr$(0)
'To show dialog, use Form1.Hwnd instead of vbAPINull.
intRet = SQLConfigDataSource(vbAPIN ull, ODBC_ADD_DSN, _
strDriver, strAttributes)
If intRet Then
MsgBox "DSN Created"
Else
MsgBox "Create Failed"
End If
Hope this helps...
Deepak.
#If WIN32 Then
Dim intRet As Long
#Else
Dim intRet As Integer
#End If
Dim strDriver As String
Dim strAttributes As String
'Set the driver to SQL Server because it is most common.
strDriver = "SQL Server"
'Set the attributes delimited by null.
'See driver documentation for a complete
'list of supported attributes.
strAttributes = "SERVER=SomeServer" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0)
strAttributes = strAttributes & "DSN=DSN_TEMP" & Chr$(0)
strAttributes = strAttributes & "DATABASE=pubs" & Chr$(0)
strAttributes = strAttributes & "UID=sa" & Chr$(0)
strAttributes = strAttributes & "PWD=" & Chr$(0)
'To show dialog, use Form1.Hwnd instead of vbAPINull.
intRet = SQLConfigDataSource(vbAPIN
strDriver, strAttributes)
If intRet Then
MsgBox "DSN Created"
Else
MsgBox "Create Failed"
End If
Hope this helps...
Deepak.
Take a look at the RegisterDatabase (of DAO) or rdoRegisterDatabase (of RDO). It registers perfectly.
ASKER
Sorry for such a long delay. Can you tell me where I can find the documentation on this topic? I can find the function declaration in MSDN, but the constant declaration of the winapi is not available. Also, driver documentation is not available :<
Thx
Thx
Hi slgal,
Long time indeed!!
As far as the documentation is concerned, check the MSDN with the foll:
HOWTO: Programmatically Create a DSN for SQL Server with VB
Constant declarations can be obtained from API Viewer or Win32api.txt file (search this file on the HDD)
Even I was not able to obtain driver specific documentation, which is something I need at times while connecting VB with Oracle/DB2, etc.
Get back anytime..
Cheers,
Deepak.
Long time indeed!!
As far as the documentation is concerned, check the MSDN with the foll:
HOWTO: Programmatically Create a DSN for SQL Server with VB
Constant declarations can be obtained from API Viewer or Win32api.txt file (search this file on the HDD)
Even I was not able to obtain driver specific documentation, which is something I need at times while connecting VB with Oracle/DB2, etc.
Get back anytime..
Cheers,
Deepak.
ASKER
Thx, even I cannot find those ODBC constant declaration in Win32api, I think it's time to give you the points :>
ASKER
Thx