Γεια σας !!! Γεια σας !!!
Παιδιά πως μπορώ προγραμματιστικά να δημιουργήσω ένα system DSN (SQL Server) ;
Βασικά, βρήκα το εξής αλλά (κάτω από SQL Server authentication) δεν μπορώ να περάσω
στα attributes τα UserId και Password :
Private Declare Function SQLDataSources Lib "ODBC32.DLL" (ByVal henv As Integer, ByVal ByValfDirection As Short, ByVal szDSN As String, ByVal cbDSNMax As Short, ByRef pcbDSN As Short, ByVal ByValszDescription As String, ByVal cbDescriptionMax As Short, ByRef pcbDescription As Short) As Short
Private Declare Function SQLAllocEnv Lib "ODBC32.DLL" (ByRef env As Integer) As Short
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal hwndParent As Integer, ByVal ByValfRequest As Integer, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Integer
Const SQL_SUCCESS As Integer = 0
Const SQL_FETCH_NEXT As Integer = 1
Private Const ODBC_ADD_DSN As Short = 1 ' Add user data source
Private Const ODBC_CONFIG_DSN As Short = 2 ' Configure (edit) data source
Private Const ODBC_REMOVE_DSN As Short = 3 ' Remove data source
Private Const ODBC_ADD_SYS_DSN As Short = 4 'Add system data source
Private Const vbAPINull As Integer = 0 ' NULL Pointer
Public Sub CreateSystemDSN()
Dim ReturnValue As Integer
Dim Driver As String
Dim Attributes As String
'Set the driver to SQL Server because it is most common.
Driver = "SQL Server"
'Set the attributes delimited by null.
'See driver documentation for a complete
'list of supported attributes.
Attributes = "SERVER=MyServer" & Chr(0)
Attributes = Attributes & "DESCRIPTION= DSN Creation TEST" & Chr(0)
Attributes = Attributes & "DSN=TESTDSN" & Chr(0)
Attributes = Attributes & "DATABASE=MyDatabase" & Chr(0)
'To show dialog, use Form1.Hwnd instead of vbAPINull.
ReturnValue = SQLConfigDataSource(vbAPINull, ODBC_ADD_SYS_DSN, Driver, Attributes)
If ReturnValue <> 0 Then
MsgBox("DSN Created")
Else
MsgBox("Create Failed")
End If
End Sub
Πάνος Αβραμίδης