Solved

putting up DSN in vb6

Posted on 2004-08-05
3
706 Views
Last Modified: 2013-12-25
g'day, i have read other people's questions about putting up DSN, and used some code in them. i find when i use the code, it's puts up the DSN that does not point to a database.

so it works, but just doesn't select the database. it's an access database. here is the code i use.

Public Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
          (ByVal hwndParent As Long, ByVal fRequest As Long, _
          ByVal lpszDriver As String, ByVal lpszAttributes As String) _
          As Long

      'Constant Declaration
      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 ODBC_ADD_SYS_DSN = 4    ' add a new system data source
      Private Const vbAPINull As Long = 0


      Dim intRet As Long
      Dim strDriver As String
      Dim strAttributes As String

      strDriver = "Microsoft Access Driver (*.mdb)"
      strAttributes = "SERVER=SomeServer" & Chr$(0)
      strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0)
      strAttributes = strAttributes & "DSN=RM TEMP" & Chr$(0)
      strAttributes = strAttributes & "DATABASE=" & App.Path & "RM.mdb" & Chr$(0)

      intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, strDriver, strAttributes)

thanks.
0
Comment
Question by:stromberg45
  • 2
3 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 11726506
I think you forgot a \

strAttributes = strAttributes & "DATABASE=" & App.Path & "\RM.mdb" & Chr$(0)
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 11726530
shouldn't it be:
strAttributes & "DESCRIPTION=Temp SN" & Chr$(0)
strAttributes = strAttributes & "DSN=RM TEMP" & Chr$(0)
strAttributes = strAttributes & "DBQ='" &  App.Path & "\RM.mdb'" & Chr$(0)
strAttributes = strAttributes & "UID=username" & Chr$(0)
strAttributes = strAttributes & "PWD=password" & Chr$(0)
0
 

Author Comment

by:stromberg45
ID: 11749636
thansk for that emoreau, worked perfectly !!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

803 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