Link to home
Start Free TrialLog in
Avatar of mgmhicks
mgmhicks

asked on

using odbc in a connection of object

How do I assign a connection object to the odbc driver  I setup in control panel to get to the database.  I know how to assign the server, but in some case I need to use the ip address and in others just the server name, so I just rather setup a odbc driver and have the connection object look at that.

thanks
Avatar of sajuks
sajuks

Check http://www.connectionstrings.com/ to setup your odbc connections strings.
Eg:for mysql
SERVER=10.160.0.101 'assumeing thats your ip
DRIVER={MySQL ODBC 3.51 Driver};DESC=;DATABASE=MyDevlpm;SERVER=10.160.0.101;UID=xxx;PASSWORD=abc;PORT=;OPTION=0;STMT=;
Hi mgmhicks,
Use this as your connection string:

DSN=MyDSN;UID=user;DATABASE=MyDatabase;PWD=MyPassword;

Failing that, drag an ODBC connection from the Data in your toolbox to the form, rightclick on it go to properties, then manually set the connection.
Check the resulting connectionstring

Dabas
sajuks,
That is a good link you posted there! Thanks!

Dabas
Avatar of mgmhicks

ASKER

Sorry guys that doesnt work.  Need to use a DSN connection in my oleconnection object.  Cant figure out the connection string.
It actually took this connection string, but the data adapter configurator doesnt see the connection object on the form.

Provider=sqloledb;Data Source=TandA;Initial Catalog=timemanagment;Integrated Security=SSPI

How do I get a data adapter to use this connection know with the data adapter configurator

mgmhicks:
Try my connection (without provider = )
DSN=TandA;UID=user;DATABASE=timemanagment;PWD=MyPassword;

Dabas
The following took care of the code.  However you must set a reference to odbc.net

        Dim cn As OdbcConnection
        cn = New OdbcConnection("dsn=TandA;uid=shicks;pwd=knicks19;")
        Dim mystring As String = "Select UserName,id from time_employees"
        Dim cmd As OdbcCommand = New OdbcCommand(mystring, cn)
        cn.Open()
I ended up putting the correct answer in myself and wasnt sure how to close it after doing that.

ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial