ich weiß nicht, ob die Idee praxistauglich ist. Unser Projekt ist da leider im Sande verlaufen ...
Ich hatte vor, die DSN zur Laufzeit zu erstellen. Vielleicht hilft es ja
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (Byval hKey As Long, Byval lpSubKey As String, phkResult As Long) As Long
Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (Byval hKey As Long, Byval lpValueName As String, Byval Reserved As Long, Byval dwType As Long, lpData As Any, Byval cbData As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" (Byval hKey As Long) As Long
.
.
.
sDSN_ZUD = "DSN_ZUD"
Call CreateDSNString (sDSN_ZUD)
.
.
.
Private Sub CreateDSNString (DataSourceName As String)
' Constant for a string variable type.
Const REG_SZ = 1
Const HKEY_LOCAL_MACHINE = &H80000002
Dim DatabaseName As String
Dim Description As String
Dim DriverPath As String
Dim DriverName As String
Dim LastUser As String
Dim Regional As String
Dim Server As String
Dim Password As String
Dim TrustedConnection As String
Dim lResult As Long
Dim hKeyHandle As Long
' Specify the DSN parameters.
DatabaseName = "<SQLDatenbank>"
Description = "Yes I can"
DriverPath = "C:\WINDOWS\system32\SQLSRV32.dll"
' LastUser = "<User>"
' Password = "<Password>"
Server = "<Servername>"
DriverName = "SQL Server"
TrustedConnection = "Yes"
' Create the new DSN key.
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" & DataSourceName, hKeyHandle)
' Set the values of the new DSN key.
lResult = RegSetValueEx(hKeyHandle, "Database", 0&, REG_SZ, Byval DatabaseName, Len(DatabaseName))
lResult = RegSetValueEx(hKeyHandle, "Description", 0&, REG_SZ, Byval Description, Len(Description))
lResult = RegSetValueEx(hKeyHandle, "Driver", 0&, REG_SZ, Byval DriverPath, Len(DriverPath))
' lResult = RegSetValueEx(hKeyHandle, "LastUser", 0&, REG_SZ, Byval LastUser, Len(LastUser))
lResult = RegSetValueEx(hKeyHandle, "Server", 0&, REG_SZ, Byval Server, Len(Server))
lResult = RegSetValueEx(hKeyHandle, "Trusted_Connection", 0&, REG_SZ, Byval TrustedConnection, Len(TrustedConnection))
' Close the new DSN key.
lResult = RegCloseKey(hKeyHandle)
' Open ODBC Data Sources key to list the new DSN in the ODBC Manager.
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources", hKeyHandle)
' Specify the new value.
lResult = RegSetValueEx(hKeyHandle, DataSourceName, 0&, REG_SZ, Byval DriverName, Len(DriverName))
' Close the key.
lResult = RegCloseKey(hKeyHandle)