Vorrei far creare direttamente alla mia applicazione un origine dati SQL Server senza far aprire le varie finestre del pannello di controllo. Cioè passandogli NomeOrigineDati, Uid, Pwd ecc. ecc. l'applicazione mi dovrebbe creare automaticamente l'origine dati (SQL Server) ODBC.
Con il seguente codice posso creare un origine dati (Access) ODBC:
codice:
'Constant Declaration
Private Const ODBC_ADD_DSN = 1 ' Add User DSN
Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
Private Const ODBC_REMOVE_DSN = 3 ' Remove data source
Private Const ODBC_ADD_SYS_DSN = 4 ' Add System DSN
Private Const vbAPINull As Long = 0& ' NULL Pointer
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
Function create(strDSN as String,strUid as String,strPwd as String, strPath as String)
Dim strDriver As String
Dim strAttributes As String
Dim lonRet As Long
strDriver = "Microsoft Access Driver (*.MDB)" & Chr$(0)
strAttributes = "DSN=" & strDSN & Chr$(0)
strAttributes = strAttributes & "Uid=" & Chr$(0) & "pwd=" & Chr$(0)
strAttributes = strAttributes & "DBQ=" & strPath & Chr$(0)
lonRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_SYS_DSN, strDriver, strAttributes)
If lonRet = 1 Then
MsgBox "DSN " & txtName.Text & " Created."
Else
MsgBox "Creation Failed"
End If
End Function
Qualcuno può aiutarmi con SQL Server?