Hello,
Instead of using the Declare statement, please also try with the DllImportAttribute to pInvoke that method. I've test the following code, and It works well on my machine.
Public Class Installer1
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add initialization code after the call to InitializeComponent
End Sub
Protected Overrides Sub OnBeforeInstall(ByVal savedState As System.Collections.IDictionary)
CreateSystemDSN()
MyBase.OnBeforeInstall(savedState)
End Sub
<DllImport("ODBCCP32.dll", CallingConvention:=CallingConvention.Winapi, CharSet:=CharSet.Unicode, SetLastError:=True)> _
Private Shared Function SQLConfigDataSource(ByVal hwndParent As Integer, ByVal fRequest As Integer, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Integer
End Function
Private Sub CreateSystemDSN()
Dim vAttributes As String = "DSN=DSN Name" & Chr(0)
vAttributes &= "Description=DSN Description" & Chr(0)
vAttributes &= "Trusted_Connection=Yes" & Chr(0)
vAttributes &= "Server=SQLINSTANCE" & Chr(0)
vAttributes &= "Database=databasename" & Chr(0)
If SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, "SQL Server", vAttributes) = 0 Then
MessageBox.Show("Failed to create ODBC data source!!")
End If
End Sub
Const ODBC_ADD_SYS_DSN As Integer = 4
End Class
As this installer actually works on the client machine, we need to make sure that MDAC is installed on the client machine, although it is installed by default after Windows XP.
Thanks,
Rong-Chun Zhang
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact
msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.