Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ODBC DSN - create and delete 1

Status
Not open for further replies.

zemp

Programmer
Jan 27, 2002
3,301
CA
I just found this on the net and decided to pass it on. It is a free ocx that provides a simple method of creating and delete DSN connections. NO API's involved (but I suspect they are part of the ocx).


Download the ocx and the test project. Don't forget to manually register the ocx with regsr32.

My preliminary test were successful and the code was easy. Here is an example of the Vb code. 'DSN1' is the default name of the ocx.

Code:
If Not DSN1.IsValid("TestDSN") Then ' if the DSN does not exist...
  DSN1.DSN = "TestDSN" ' set the DSN name
  DSN1.ServerName = "SERVER01" ' set the server name
  DSN1.Database = "MyDatabase" ' set the database name
  DSN1.UserName = "uid" ' your user id
  DSN1.Password = "pwd" ' your password
  DSN1.ODBCDriver = "SQL Server" 'this is the default value
  DSN1.Description = "This is a description" ' set the description
  DSN1.TrustedConnection = "Yes" ' make connection trusted
  If DSN1.AddDSN Then ' if the add worked...
    DSN1.DeleteDSN ' demonstrate delete
  End If
End If

Hope someone finds this useful.

Thanks and Good Luck!

zemp
 
I have previosly used rdoEngine.rdoRegisterDataSource to create a DSN on the fly (no API) - does this ocx achieve something different or ist it just an alternative?
 
That said, I don't think there is a Delete equivalent.
 
Not being familiar with rdo.Engine.... I would have to guess that it would be more of an alternative.

Thanks and Good Luck!

zemp
 
It took me a while to stumble across it! Looks something like this:

strAttribs = "Description=Test DSN" _
& vbCr & "OemToAnsi=No" _
& vbCr & "SERVER=MyServer" _
& vbCr & "Network=DBNMPNTW" _
& vbCr & "Trusted_Connection=Yes" _
& vbCr & "Database=MyDb" rdoEngine.rdoRegisterDataSource DSNName, _
"SQL Server", True, strAttribs

Though, as I say, no delete option that I am aware of. Also need to add Microsoft Remote Data Object to project references.
 
Dear Zemp
I have registered dsn.ocx
but tell me where I have to paste the piece of code
u said
is it in formlaod
dsn1. its saying object not found

pls help
Alisha
 
You need to add the dsn ocx control to your project components and then find it in youn tool box and draw it on your form. Set it's .visible property to false. Then you can paste the code wherever you need to use it. Check the test project and make yours similar (as far as this ocx setup is concerned).

Thanks and Good Luck!

zemp
 
But its not shown in availble odbc datasources
I gave the code in form load of main form.
will it register automatically the source
 
DSN1 is the name given to the instance of the control by VB. In the odbc system data sources you would be looking for the name 'testDSN'.

Check the name given to the control, either by VB or by you. Make sure it and the name of the object in the code are the same. If you are still stuck post your code. Have you downloaded and looked at the text project?



Thanks and Good Luck!

zemp
 
Hi:

I am trying to use the DSN.ocx to connect to an Access db.
I am getting an error message.

What am I supposed to place at:
DSN1.SERVERNAME
DSN1.ODBCDRIVER

What about Username and Password??

I will appreciate your help.

Thanks.

Chequi.



 
Hi:

The error message looks like the following:

error SQLConfigDataSource() Component not found in the registry DSN=TestDSN\0SERVER=CAT-OZ5MV0UIEZ8\0DATABASE=c:\program files\oegreport\oegdb.mdb \0DESCRIPTION=Test HendriCOM Source\0\0

(CAT-... is MyComputer Name)

Chequi.
 
I am not sure for Access, I have only used it for SQL server. You can try their Message board.


Take Care,

zemp

"Show me someone with both feet on the ground and I will show you someone who can't put their pants on."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top