Hi all,
How to create a DSN programmatically?
I need to create a system DSN in about 100 systems. So, If I create a program to do that it will be easier for me. So, pls help me to do that!
Thanks,
CS.
Printable View
Hi all,
How to create a DSN programmatically?
I need to create a system DSN in about 100 systems. So, If I create a program to do that it will be easier for me. So, pls help me to do that!
Thanks,
CS.
You don't actually need to use DSN's at all. You can connect to most (all?) databases by simply specifying the relevant information in a connection string.
This not only makes your "nightmare" installation easier, it also bypasses the problem of ODBC being removed in future (which is likely to happen, especially in 64bit Windows).
You may be able to find the details you need in the Connection Strings link below, if not give us more details :)
i used this to create my DSN. then just called Connect on my main form. works fine for me. Its for an access database. think it will work well for others as well
VB Code:
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 Public DB As ADODB.Connection Public connString As String Public Sub Connect() Call Create connString = "DSN=VRRS;" Set DB = New ADODB.Connection DB.Open connString End Sub Private Function CreateAccessDSN(DSNName As String, DatabaseFullPath As String) As Boolean Dim sAttributes As String sAttributes = "DSN=" & DSNName & Chr(0) sAttributes = sAttributes & "DBQ=" & DatabaseFullPath & Chr(0) CreateAccessDSN = CreateDSN("Microsoft Access Driver (*.mdb)", sAttributes) End Function Private Function CreateDSN(Driver As String, Attributes As String) As Boolean CreateDSN = SQLConfigDataSource(0&, 1, Driver, Attributes) End Function Private Sub Create() Dim blnRetVal As Boolean blnRetVal = CreateAccessDSN("VRRS", "C:\VRRS\VRRS.mdb") End Sub
Ok, fine! this is for Access. what about Oracle? Thanks a lot. CS.
Using one of these connection strings (instead of using a data source) should work for you, thus eliminating the need to set up a DSN as part of your installation:
"Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=Username;Pwd=password;"
"Driver={Microsoft ODBC Driver for Oracle};ConnectString=OracleServer.world;Uid=myUsername;Pwd=password;"
I use ADO code to connect my access database. so, what is the connection string to eliminate the DSN?
Have you tried te suggestions in Post #5? You could also take a look at www.connectionstrings.com for guidance...
Thanks! great site!
No worries... :)