mulga
asked on
Creating DSN
I have a VB6 program that uses a MSAccess MDB from a Dataenvironment connection. On my machine I know path to the MDB for all my data control sources. These tend to get hardwired into the program which is not a problem in development BUT on my clients machines I will not know where the MDB will be except that it will be in the App.Path, the Dataenviroment insists in putting the full path. If I use a DSN how can to create one on installation on the client's machine or is it possible to create one when the program starts ie
Pseudo code
Program start
'Check if DSN exists
if test_DSN exists continue
else
test_DSN =create_dsn( app.path & "test.mdb")
End if
Now the Dataenviroment1 can access the test_DSN
Is this possible or is there a better way to do this
Pseudo code
Program start
'Check if DSN exists
if test_DSN exists continue
else
test_DSN =create_dsn( app.path & "test.mdb")
End if
Now the Dataenviroment1 can access the test_DSN
Is this possible or is there a better way to do this
If you look at a DSN file, you'll see that it's just a text file with parameters in it, you should be able to just create a file in the appropriate directory (wherever your DSN's sit) and you should be able to call it from there. I've not tried this, so just give it a go.... and good luck.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
' paste this to a form
Option Explicit
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal HM As Integer, ByVal Rq As Integer, ByVal Driver As String, ByVal Connect As String) As Integer
Private Sub Form_Click()
Dim rc As Integer, sName As String, sMDB As String
sName = "MulgaDSN"
sMDB = "c:\vb5\biblio.mdb" ' ( app.path & "test.mdb")
rc = SQLConfigDataSource(0, 1, "Microsoft Access Driver (*.mdb)", "DSN=" & sName & Chr(0) & "DBQ=" & sMDB & Chr(0) & Chr(0))
' return code 0 means failure
If rc = 0 Then
MsgBox "Could not configure data source."
End If
End Sub
Option Explicit
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal HM As Integer, ByVal Rq As Integer, ByVal Driver As String, ByVal Connect As String) As Integer
Private Sub Form_Click()
Dim rc As Integer, sName As String, sMDB As String
sName = "MulgaDSN"
sMDB = "c:\vb5\biblio.mdb" ' ( app.path & "test.mdb")
rc = SQLConfigDataSource(0, 1, "Microsoft Access Driver (*.mdb)", "DSN=" & sName & Chr(0) & "DBQ=" & sMDB & Chr(0) & Chr(0))
' return code 0 means failure
If rc = 0 Then
MsgBox "Could not configure data source."
End If
End Sub
ASKER
That worked OK, BUT since doing that I have found installing ADO so problematic that I have decided to go back to DAO. A file that had an installation size of 1.9 MB blows out to 9.6 MB with DCOM and MDAC_TYP etc. Also had problems with some computers failing for some unknown reason . THe documentation is so shitty ----- Jeez!
Agreed Mulga - It doesn't help with the transition between DAO and ADO when it has so many 'features'...
how to insert values to the database from a command button click through insert statement
my insert statement is like this
insert into dept1 values (text1.text,'text2.text',' text3.text ')
Option Explicit
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Form_Load()
conn.Open "Provider=SQLOLEDB.1;Persi st Security Info=False;User ID=sa;pwd=softprojex;Initi al Catalog=pubs;Data Source=MICROSOFTTEST"
rs.Open "Select * from dept1", conn, adOpenKeyset
Set rs = Nothing
End Sub
please help me with code
thanks and regards
satishpreddy
my insert statement is like this
insert into dept1 values (text1.text,'text2.text','
Option Explicit
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Form_Load()
conn.Open "Provider=SQLOLEDB.1;Persi
rs.Open "Select * from dept1", conn, adOpenKeyset
Set rs = Nothing
End Sub
please help me with code
thanks and regards
satishpreddy