Solved

Adding an ODBC connection

Posted on 2006-06-15
6
230 Views
Last Modified: 2010-04-07
Hello,

I have a toolbar that needs to do some SQL Database lookups from 50 user desktops.  I need to create an ODBC connection for each the first time the user needs to use it.

The toolbar starts at startup and needs to check to see if the ODBC connection is there
If not, i need to create it as a system ODBC connection

I have tried to add the keys using group policy but it is not working for some reason.

Any help is greatly appreciated!!!! ----  URGENT!

Eric
0
Comment
Question by:posae
  • 3
  • 3
6 Comments
 

Author Comment

by:posae
ID: 16912768
Oh Yea...the app is in VB6
0
 
LVL 18

Accepted Solution

by:
mirtheil earned 500 total points
ID: 16912885
You can use SQLConfigDataSource ODBC API call.  Here's a link that shows how to do it for Access but can be modified for other databases:
http://support.microsoft.com/?kbid=231156
0
 

Author Comment

by:posae
ID: 16920957
thanks mirtheil...what attributes do I have to include?
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 18

Expert Comment

by:mirtheil
ID: 16921032
It depends on the DBMS you are using.  You'll basically include all of the keyword pairs that make up a DSN.  
0
 

Author Comment

by:posae
ID: 16921249
This is what I have in the code and it keeps erroring out...any ideas?

Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal hwndParent As Long, ByVal fRequest As Long, ByVallpszDriver As String, ByVal lpszAttributes As String) As Long

Private Function Build_SystemDSN()
Dim ReturnValue As Integer
Dim Driver As String
Dim Attributes As String


   Driver = "SQL Server" & Chr(0)
   Attributes = "SERVER=samcoapps" & Chr(0)
   Attributes = Attributes & "DESCRIPTION=New DSN" & Chr(0)
   Attributes = Attributes & "DSN=DSN_TEMP" & Chr(0)
   Attributes = Attributes & "DATABASE=CRM" & Chr(0)
   
   ret = SQLConfigDataSource(0, 4, Driver, Attributes)
   
   'ret is equal to 1 on success and 0 if there is an error
   If ret <> 1 Then
       MsgBox "DSN Creation Failed"
   End If

End Function


0
 
LVL 18

Expert Comment

by:mirtheil
ID: 16921515
Here's a link to some code.  I haven't worked with SQL Server.  THe code below did create the DSN for me (but I can't test the DSN since I don't have SQL Server installed)
http://www.freevbcode.com/ShowCode.Asp?ID=502

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 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