Hi,
I have a Access database (2003) that is linked to the SQl server, through upsizing.
I made a new table on the sqlserver and linked it to my access database.
Therefor I needed to make an user dsn or System DSn. When I copy the database to another computer the one link (through DSn) does not work. Can I use Visual BAsic to make the link when opening the database? How to I have to do this?
I’ve already tried some stuff found on the internet, but it doesn’t to the thing.
Option Explicit
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 Const ODBC_ADD_SYS_DSN = 4
Public Function CreateSQLServerDSN(DSNName As String, _
ServerName As String, Database As String) As Boolean
‘PURPOSE: ‘CREATES A SYSTEM DSN FOR AN SQL SERVER DATABASE
‘PARAMETERS: ‘DSNName = DSN Name
‘ServerName = Name of Server
‘Database = Database to Use
‘RETURNS: True if successful, false otherwise
‘EXAMPLE: CreateSQLServerDSN “MyDSN”, “MyServer”, “MyDatabase”
Dim sAttributes As String
sAttributes = “DSN=” & DSNName & Chr(0)
sAttributes = sAttributes & “Server=” & ServerName & Chr(0)
sAttributes = sAttributes & “Database=” & Database & Chr(0)
CreateSQLServerDSN = CreateDSN(“SQL Server”, sAttributes)
End Function
Function autoexec()
MsgBox CreateSQLServerDSN(“name dsn”, “name SQlserver”, “name SQlserver database”)
End Function
whan I run this application, the messagebox has a value “true”. When i check the ODBC there is no user dsn or system dsn made.
Is my code wrong or do I have to do something else?