Forum Settings
       
Reply To Thread

Geek QuestionFollow

#1 Oct 30 2006 at 12:21 PM Rating: Good
Mark this one on your calendars as the first time Eld has asked you a question. It is a rarity since I know pretty much everything. Whatever I don't know, I expect you guys to know it, therefore making everything right in the world.

Now then, a Smiley: cookie for (s)he who can answer this question:


How do you do a cross ODBC-DSN query?

Example solution using middleware:

MSACCESS DB
> Linked MS-SQL Table
> Linked ORACLE table
> Linked Text file DSN table

QUERY: INSERT into MS-SQL table SELECTing from Text file with a JOIN on the Oracle table.


PROBLEM:
How do you do this without the middleware in any common programming language available. (Bonus points for ASP, VB.NET, C#, C++ solutions). Pseudo code accepted if you can back up the concept with fact.


Edit: 1 rule. You must accomplish this in one(1) Query. Loops per record are not allowed.

GO!





Edited, Oct 30th 2006 at 12:24pm PST by Elderon
#2 Oct 30 2006 at 12:26 PM Rating: Excellent
Avatar
******
29,919 posts
the vb.net 2005 developer pack will generate the odbc string for you.
____________________________
Arch Duke Kaolian Drachensborn, lvl 95 Ranger, Unrest Server
Tech support forum | FAQ (Support) | Mobile Zam: http://m.zam.com (Premium only)
Forum Rules
#3 Oct 30 2006 at 12:48 PM Rating: Good
Pumpkin Lörd Kaolian wrote:
the vb.net 2005 developer pack will generate the odbc string for you.
Whachho talkin bout Willis? I have ODBC strings for all three databases and can connect swimmingly. A cross-DSN query is the question.
#4 Oct 30 2006 at 12:53 PM Rating: Decent
Is this one of those "I know the answer and want to brag" or do you genuinely need to figure this out?

What do you have against the middleware?
#5 Oct 30 2006 at 12:55 PM Rating: Good
*****
19,369 posts
Do your own homework, cUnt.
#6 Oct 30 2006 at 1:19 PM Rating: Good
MentalFrog wrote:
Do your own homework, cUnt.
Back in my day we never had homework. We just had work and didn't bother with your fancy book-learner classifications, ya **** waffle.

I put this infront of the geek minds here because this is something you either know or know someone who knows it because it's very difficult to find anything on the topic.


Professor CrescentFresh wrote:
Is this one of those "I know the answer and want to brag" or do you genuinely need to figure this out?
Wouldn't you like to know.


Professor CrescentFresh wrote:
What do you have against the middleware?
Middleware is like a guy-guy-girl sandwich. Eww. Just eww..
#7 Oct 30 2006 at 1:21 PM Rating: Decent
Elderon the Wise wrote:
Professor CrescentFresh wrote:
Is this one of those "I know the answer and want to brag" or do you genuinely need to figure this out?
Wouldn't you like to know.
If you are just looking to brag let's go ahead and skip to that part. I don't know how to do it and have never even considered doing something like this before, but now that you asked the question I am curious.
#8 Oct 30 2006 at 1:48 PM Rating: Good
Professor CrescentFresh wrote:
Elderon the Wise wrote:
Professor CrescentFresh wrote:
Is this one of those "I know the answer and want to brag" or do you genuinely need to figure this out?
Wouldn't you like to know.
If you are just looking to brag let's go ahead and skip to that part. I don't know how to do it and have never even considered doing something like this before, but now that you asked the question I am curious.
I already told you that I know everything, if not myself then by proxy. In this case I am hoping that I know it by proxy.
#9 Oct 30 2006 at 1:55 PM Rating: Good
Imaginary Friend
*****
16,112 posts
Quote:
I already told you that I know everything, if not myself then by proxy.



I would totally sig this were it not for my ultra-spiffy undead-language quote.
____________________________
With the receiver in my hand..
#10 Oct 31 2006 at 3:51 AM Rating: Good
I'll check with the other devs in my area now that I have my spiffy new application developer job. I've never actually tried to connect to all three in one string, sure each individually (I prefer using OleDB rather than ODBC) but I imagine someone around me would have an idea of how it's done.
#11 Oct 31 2006 at 5:06 AM Rating: Default
**
301 posts
Eld,
If you have access to the ado.net control, that should allow you to make the connect to both Db's as well as the text file.

at least that's what the dev's and dba's here said
#12 Oct 31 2006 at 7:07 AM Rating: Good
Wint wrote:
I've never actually tried to connect to all three in one string, sure each individually
Exactly.

KriegsmaschineVondentoten wrote:
Eld,
If you have access to the ado.net control, that should allow you to make the connect to both Db's as well as the text file.

at least that's what the dev's and dba's here said
But can you make a cross DB query? Smiley: dubious
#13 Oct 31 2006 at 7:19 AM Rating: Good
Elderon,

You can do it, but not all within .NET. You can only connect to one datasource at a time.

How this is commonly one is to connect to one database, build your dataset, then insert that into another database, with a new connection.

Outside of using middleware, or linked servers, you cannot connect to multiple databases with one connection object, at least in .NET.

EDIT:

This can be done with SQL 2005 Integration Services, which is part of SQL 2005 and VS.NET 2005. You can create multiple connections to data sources, create your transform packages, and load the data back into another database.

Edited, Oct 31st 2006 at 7:22am PST by Frakkor
#14 Oct 31 2006 at 7:27 AM Rating: Default
**
301 posts
Quote:
But can you make a cross DB query?


According to the folks here, yes, the ado object will allow you to query both the Oracle and SQL dbs as well as the text file as if it were a table. We use a similar approach for one of our cross DB applications where we use a text file to tie out 2 different tables in 2 different DBs.
#15 Oct 31 2006 at 8:02 AM Rating: Good
**
448 posts
If it's a one-time thing and you want to do it solely in .NET, I think your best bet is to load the Oracle and Text data into a dataset with relations between the tables, and then push it to SQL with a data adapter.

If you want to do it in one query and you'll be setting up a process to be reused, I think your best bet would be linked servers (haven't used integration services with SQL2005, but I suspect it works similarly). Then you can create a stored procedure to pull joined data between the Text and Oracle sources into a sql table with one statement.
#16 Oct 31 2006 at 10:13 AM Rating: Decent
*****
10,755 posts
This is the biggest uber geek circle-jerk I've ever seen.
#17 Oct 31 2006 at 10:49 AM Rating: Good
Frakkor wrote:
Elderon,

You can do it, but not all within .NET. You can only connect to one datasource at a time.

How this is commonly one is to connect to one database, build your dataset, then insert that into another database, with a new connection.

Outside of using middleware, or linked servers, you cannot connect to multiple databases with one connection object, at least in .NET.

EDIT:

This can be done with SQL 2005 Integration Services, which is part of SQL 2005 and VS.NET 2005. You can create multiple connections to data sources, create your transform packages, and load the data back into another database.


Sounds interesting. I've already solved the issue for the time being by simple opening one recordset, iterating through the records and writing them one-by-one to the other dataset until rs = EOF. It works very well, but I'd like to make it into a sexy single INSERT query because I'm hoping to gain performance.


KriegsmaschineVondentoten wrote:
Quote:
But can you make a cross DB query?


According to the folks here, yes, the ado object will allow you to query both the Oracle and SQL dbs as well as the text file as if it were a table. We use a similar approach for one of our cross DB applications where we use a text file to tie out 2 different tables in 2 different DBs.
can you get more info on this? I use the (ADODB) object and have multiple connections open at once, but the problem is that if you write a nice insert query from the defined table in connection "a" and want to just pop those records into connection "b", the problem is that the query has to be assigned to one connection only ie: rs.open strSQL, db. Unless it is handled at the DB server like cross-DB queries in MSSQL where you specify the dbname.owner.table, how do you do it? Smiley: dubious



NephthysWanderer the Charming wrote:
This is the biggest uber geek circle-jerk I've ever seen.
Well uber geeks usually do have uber large penises, so it just makes logical sense.


#18 Oct 31 2006 at 11:15 AM Rating: Good
**
448 posts
Quote:
Sounds interesting. I've already solved the issue for the time being by simple opening one recordset, iterating through the records and writing them one-by-one to the other dataset until rs = EOF. It works very well, but I'd like to make it into a sexy single INSERT query because I'm hoping to gain performance.


Linked servers are the way to get that single INSERT query.

INSERT [SqlTable]
SELECT extDb1.Field1 extDb2.Field FROM [ExternalDataProvider1].[ExternalDBName].[ExternalDBO].[ExternalDataTable] as extDb1
JOIN
[ExternalDataProvider2].[ExternalDBName].[ExternalDBO].[ExternalDataTable] as extDb2 ON extDb1.PriKey = extDb2.PriKey

Sexy, right?

If you need to use ADODB, you can, but unless there's a way I don't know to push an entire recordset without iterating though it, you're stuck doing that. I believe you can reassign the connection of your recordset with "SET rs.ActiveConnection = newConn".

Edited, Oct 31st 2006 at 11:23am PST by sulleih
#19 Oct 31 2006 at 4:10 PM Rating: Good
sulleih wrote:
Quote:
Sounds interesting. I've already solved the issue for the time being by simple opening one recordset, iterating through the records and writing them one-by-one to the other dataset until rs = EOF. It works very well, but I'd like to make it into a sexy single INSERT query because I'm hoping to gain performance.


Linked servers are the way to get that single INSERT query.
That's what I was afraid of. Unfortunately, this does not bode well for a dynamic ODBC connection to a text file. I guess I'll just have to stick with my current solution that works really well, but isn't quite as sexy.
#20 Nov 01 2006 at 5:09 AM Rating: Good
**
448 posts
Eldy wrote:
That's what I was afraid of. Unfortunately, this does not bode well for a dynamic ODBC connection to a text file. I guess I'll just have to stick with my current solution that works really well, but isn't quite as sexy.


You're not blown out of the water yet!

This is a good article that outlines how to use the Jet ODBC driver to create a Linked Server to a text file.

There's some setup issues, of course (creating schema.ini, etc). There's also setup issues with the Oracle connection (making sure you have the Oracle provider installed correctly on the SQL server and stuff). If you're creating a reusable procedure for an app, though, I think this is definitely the way to go to get that server-side processing and help with app performance.
#21 Nov 01 2006 at 5:12 AM Rating: Good
**
448 posts
Another good article (from MSDN) on creating linked servers (including to a text file).
#22 Nov 01 2006 at 4:09 PM Rating: Default
So happy I couldn't answer that question.
Reply To Thread

Colors Smileys Quote OriginalQuote Checked Help

 

Recent Visitors: 226 All times are in CST
Anonymous Guests (226)