PDA

Click to See Complete Forum and Search --> : Creating a DSN for Text Database through Code


Suman
Oct 30th, 2000, 03:21 AM
Can any body out there Show me the Code for Programmatically creating a DSN for Connecting to a text Database .


Thanks

SteveFlitIII
Oct 30th, 2000, 03:54 AM
You can create a DSN using RDO's rdoRegisterDataSource method.
If you need the code I can produce some for you.

TheBao
Feb 18th, 2001, 05:15 PM
Hi,

I know how to create a User DSN using rdoRegisterDataSource method. Do you know how to create the System DSN using code?

Regards,
TheBao

ayyasaran
Feb 19th, 2001, 12:00 AM
Hi,

The following API can be used to create a user, system DSN.

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

Regards,
Saran.

Vit
Feb 19th, 2001, 06:02 AM
Here's fully functional routines for creating/deleting DSN


'Declarations Used to Generate DSN
Private Const ODBC_ADD_DSN = 1 ' Add data source
Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
Private Const ODBC_REMOVE_DSN = 3 ' Remove data source
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

Public Sub CreateDSN(sDSN As String)
Dim nRet As Long
Dim sDriver As String
Dim sAttributes As String

sDriver = "Oracle73 Ver 2.5"
sAttributes = "Server=pressdb.world" & Chr$(0)
sAttributes = sAttributes & "DESCRIPTION=" & sDSN & Chr$(0)
sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)
sAttributes = sAttributes & "DATABASE=DB" & Chr$(0)
sAttributes = sAttributes & "UID=Vital" & Chr$(0)
sAttributes = sAttributes & "PWD=myPassword" & Chr$(0)

DBEngine.RegisterDatabase "kiki", "Oracle73 Ver 2.5", True, sAttributes

nRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN, sDriver, sAttributes)

End Sub

Public Sub DeleteDSN(sDSN As String)
Dim nRet As Long
Dim sDriver As String
Dim sAttributes As String

sDriver = "Oracle73 Ver 2.5"
sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)

nRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, sDriver, sAttributes)

End Sub

Have fun!