Programmatically creating a DSN

M

Mart

Thanks for the post I've had back on this .... but it's
not quiet what I need.

I'm trying to create this programmatically. So that the
DNS does not have to be set up for the machine / user
first.

Can anyone help with this....?

I'm using a IBM DB2 database. I have the server name, db
name etc... but what is the SVRname,Silent and ODBCAttr
arguments?

Any tips would be welcome.


CreateDSN(DSNname As String, ODBCDriver As String,
SVRname As String, _
DBname As String, USER As String, PWD
As String, DSNdesc As String, _
Silent As Boolean, ODBCAttr As
String) As Boolean

Thanks

M.
...
 
I

Ivar Svendsen

Hello.

This code is right out of my own installation program:

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

Const ODBC_ADD_SYS_DSN = 4

S = "DSN=StvkXP" & Chr(0)
S = S & "Description=ODBC-Kobling til StvkXP" & Chr(0)
S = S & "DBQ=" & DATA.Name & Chr(0)
S = S & "SystemDB=" & szMDW & Chr(0)
S = S & "UID=Bruker" & Chr(0)
S = S & "PWD=" & Chr(0)

SQLConfigDataSource 0, ODBC_ADD_SYS_DSN, "Microsoft
Access Driver (*.mdb)", S

This will create the .DSN file required to do open a
connection with ADO or DAO.

But of course, you could just write something like

Workspace(0).OpenConnection
("Test", "DBQ=Test.mdb;SystemDB=Test.mdw;UID=Bruker;PWD=")

The easiest way to determine this string is to manually
configure the connection by means of the ODBC dialog, and
then read either the Connect property or the DNS file to
find the parameters, and implement that string in the
program.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top