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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use 2 ODBC in on form?

Status
Not open for further replies.

creedprg

MIS
Aug 31, 2005
18
PH
Hello Guys;

I'de like to use 2 ODBC driver in on form, the logic is that to access different database.


thanks
 


ok... im using MS SQL as my back end database installed in my 2003 server. on my Pc i have 2 odbc driver odbc1 connect to database1 and odbc2 connect to database2. I wish to access this two database in one form. is it possible?
 
Are you saying that that you have two separate ODBC drivers? If so, that doesn't make sense. The ODBC driver is specific to the back end. If you are using "MS SQL" (SQL Server?), then you only need a driver for that back end. It doesn't matter how many databases you have on the back end. You will only need one driver.

If you are asking how to access two databases from the same form, that's another matter. Assuming you are using SQL Server, you simply add the database name to the table / schema path, using a dot as the separator. So, for example, if you want to get data from a Customer table, you would normally do this:

Code:
SELECT Name, ID, ... FROM Customer

This assumes that Customer is a table in the default database.

But if you want to get data from a Customer table in a different database, you would do this:

Code:
SELECT Name, ID, ... FROM [b]Test.[/b]dbo.Customer

where Test is the name of the database (and dbo is a place-holder for the schema name).

Keep in mind that the above syntax is specific to SQL Server. It will be different for other back ends.

Does that answer your question?

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
@Mike Lewis (Edinburgh, Scotland) thanks for help sir, problem has been solved by following your given instruction "SELECT Name, ID, ... FROM Test.dbo.Customer " I have specified the database where the table is stored.

Thank you so much!!!!



jess
 
Well, if you are using several servers for different databases you can't solve that by using DBName.dbo.Tablename

Also depends much on the remote database access you use, there are several options: Remote View, SQL Passthrough (SQLExec etc) and Cursoradapters. If you are using remote views, you define Connections in a view DBC and you can have as many Connection objects within a DBC as you need.

If you are using cursor adapters, sqlexec or anything needing a connection handle, then you simply make several connections.

Code:
h1 = sqlstringconnect("...server=Server1;database=DB1;....)
h2 = sqlstringconnect("...server=Server2;database=DB2;....)

And then use these two connections eg SQLExec(h1,"query to DB1 of Server1") and SQLExec(h2,"query to DB2 ofServer2").

Bye, Olaf.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top