Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Creating DSN

Posted on 1999-08-01
6
Medium Priority
?
424 Views
Last Modified: 2013-12-25
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

0
Comment
Question by:mulga
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 10

Expert Comment

by:smegghead
ID: 1507355
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.
0
 

Accepted Solution

by:
bito_se earned 300 total points
ID: 1507356
You could specify the full path in the dataenvironment and then change the connectionstring using App.path in the dataenvironments initialize event. If your dataenvironment contains several connections you will of course have to repeat this procedure for every connection. Hope this is sufficient:

private sub denDataEnvironment_Initialize()

denDataEnvironment.cnnConnection.ConnectionString = "DBQ=" & App.Path & "\MyDatabase.mdb;Driver={Microsoft Access Driver (*.mdb)};"

end sub

regards,

Tomas


0
 
LVL 15

Expert Comment

by:ameba
ID: 1507357
' 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

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:mulga
ID: 1507358
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!
0
 
LVL 10

Expert Comment

by:smegghead
ID: 1507359
Agreed Mulga - It doesn't help with the transition between DAO and ADO when it has so many 'features'...
0
 

Expert Comment

by:satishpreddy
ID: 11970382
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;Persist Security Info=False;User ID=sa;pwd=softprojex;Initial 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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question