Hi,
I have a module that create the system DSN (odbc) and it works. Now i need to modify this module to add a server Alias with port number for a connection to SQL Server. I searched all over the internet but found nothing regarding the option for port number and server alias. I tried adding the keyword "port=" and assign the port number but it doesn't work. The code shown below works without the Port option
Is there a way to accomplish this task using the existing code?
Any input is much appreciated.
Thanks,
I have attached the images of the process to create the server alias using "odbcad32".
I have a module that create the system DSN (odbc) and it works. Now i need to modify this module to add a server Alias with port number for a connection to SQL Server. I searched all over the internet but found nothing regarding the option for port number and server alias. I tried adding the keyword "port=" and assign the port number but it doesn't work. The code shown below works without the Port option
Code:
& Chr$(0) & _
"Port=" & sPort
Any input is much appreciated.
Thanks,
I have attached the images of the process to create the server alias using "odbcad32".
Code:
Option Compare Database
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
Public Function MakeDSNx(sDSN As String, sServer As String, sDB As String, sDesc As String, sPort As String)
'Create ODBC System Data Source
Dim lngRet As Long
Dim strAttributes As String
'Set the detail of DSN
strAttributes = "Dsn=" & sDSN & Chr$(0) & _
"Server=" & sServer & Chr$(0) & _
"Database=" & sDB & Chr$(0) & _
"Description=" & sDesc & Chr$(0) & _
"Trusted_Connection=Yes" [B][COLOR=Magenta]& Chr$(0) & _
"Port=" & sPort[/COLOR][/B]
'Create DSN
'0& = Null, 4 = Add a System DataSource
lngRet = SQLConfigDataSource(0&, 4, "SQL Server", strAttributes)
If lngRet = 0 Then
MsgBox Err.Description
End If
End Function
Function tsx()
Call MakeDSNx("VirtualX", "VirtualX", "VirtualX", "VirtualX", 1234)
End Function