Unix Technical Forum

Stored Procedure querying another database

This is a discussion on Stored Procedure querying another database within the SQL Server forums, part of the Microsoft SQL Server category; --> Hello, I need to come up with a stored procedure that will allow me to read data from another ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 01:15 PM
mkarbarz@gmail.com
 
Posts: n/a
Default Stored Procedure querying another database

Hello,

I need to come up with a stored procedure that will allow me to read
data from another database. The database I need to read the data from
is a UniData residing on a Unix server. The stored procedure needs to
reside on my sql 2005 server. The task is very simple in Access as we
have ODBC connections set up to the UniData via Informix (or IBM)
UniData ODBC drivers. I can easily combine my UniData and Sql Server
tables from within access. However, I can't seem to find a way to
replicate the same behavior in MS SQL Stored Procedure without the use
of Access. Is that even possible?

Thanks,

Marek

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 01:15 PM
Steve
 
Posts: n/a
Default Re: Stored Procedure querying another database

On Feb 6, 1:25 pm, "mkarb...@gmail.com" <mkarb...@gmail.com> wrote:
> Hello,
>
> I need to come up with a stored procedure that will allow me to read
> data from another database. The database I need to read the data from
> is a UniData residing on a Unix server. The stored procedure needs to
> reside on my sql 2005 server. The task is very simple in Access as we
> have ODBC connections set up to the UniData via Informix (or IBM)
> UniData ODBC drivers. I can easily combine my UniData and Sql Server
> tables from within access. However, I can't seem to find a way to
> replicate the same behavior in MS SQL Stored Procedure without the use
> of Access. Is that even possible?
>
> Thanks,
>
> Marek


Linked server or OPENROWSET
In SQL Server 2005 Books Online see the topic: Distributed Queries

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 01:15 PM
mkarbarz@gmail.com
 
Posts: n/a
Default Re: Stored Procedure querying another database

On Feb 6, 5:09 pm, "Steve" <morrisz...@hotmail.com> wrote:
> On Feb 6, 1:25 pm, "mkarb...@gmail.com" <mkarb...@gmail.com> wrote:
>
> > Hello,

>
> > I need to come up with a stored procedure that will allow me to read
> > data from another database. The database I need to read the data from
> > is a UniData residing on a Unix server. The stored procedure needs to
> > reside on my sql 2005 server. The task is very simple in Access as we
> > have ODBC connections set up to the UniData via Informix (or IBM)
> > UniData ODBC drivers. I can easily combine my UniData and Sql Server
> > tables from within access. However, I can't seem to find a way to
> > replicate the same behavior in MS SQL Stored Procedure without the use
> > of Access. Is that even possible?

>
> > Thanks,

>
> > Marek

>
> Linked server or OPENROWSET
> In SQL Server 2005 Books Online see the topic: Distributed Queries


I started playing around with the linked server and I got it to the
point where I can see the tables from UniData, but when I try to query
it using LINKEDSERVERNAME...TABLE I get 'Invalid schema or catalog
specified for provider 'MSDASQL'." error. When I try to specify
schema using LINKEDSERVERNAME.SCHEMA.TABLE I get 'Invalid object name
LINKEDSERVERNAME.SCHEMA.TABLE'; do you know why these errors occur
and how to get around them?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-01-2008, 01:15 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Stored Procedure querying another database

mkarbarz@gmail.com (mkarbarz@gmail.com) writes:
> I started playing around with the linked server and I got it to the
> point where I can see the tables from UniData, but when I try to query
> it using LINKEDSERVERNAME...TABLE I get 'Invalid schema or catalog
> specified for provider 'MSDASQL'." error. When I try to specify
> schema using LINKEDSERVERNAME.SCHEMA.TABLE I get 'Invalid object name
> LINKEDSERVERNAME.SCHEMA.TABLE'; do you know why these errors occur
> and how to get around them?


To refer to an object on a remote server, you must use four-part
notation: server.catalog.schema.table. So that's why
INKEDSERVERNAME.SCHEMA.TABLE does not work.

Unfortunately, I have no idea what will work, since I've never heard of
Unidata before.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-01-2008, 01:15 PM
mkarbarz@gmail.com
 
Posts: n/a
Default Re: Stored Procedure querying another database

On Feb 6, 6:07 pm, Erland Sommarskog <esq...@sommarskog.se> wrote:
> mkarb...@gmail.com (mkarb...@gmail.com) writes:
> > I started playing around with the linked server and I got it to the
> > point where I can see the tables from UniData, but when I try to query
> > it using LINKEDSERVERNAME...TABLE I get 'Invalid schema or catalog
> > specified for provider 'MSDASQL'." error. When I try to specify
> > schema using LINKEDSERVERNAME.SCHEMA.TABLE I get 'Invalid object name
> > LINKEDSERVERNAME.SCHEMA.TABLE'; do you know why these errors occur
> > and how to get around them?

>
> To refer to an object on a remote server, you must use four-part
> notation: server.catalog.schema.table. So that's why
> INKEDSERVERNAME.SCHEMA.TABLE does not work.
>
> Unfortunately, I have no idea what will work, since I've never heard of
> Unidata before.
>
> --
> Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se
>
> Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
> Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx


I started using the 4 part query and I guess I got a step further;
now I'm getting a different error:

the query is: SELECT * FROM AVLIVE..ii.SODET_NF

the error:
[OLE/DB provider returned message: Unspecified error]
[OLE/DB provider returned message: [Ardent][UniData ODBC
Driver]Invalid column number.]
OLE DB error trace [OLE/DB Provider 'MSDASQL'
IDBSchemaRowset::GetRowset returned 0x80004005: ].
Msg 7399, Level 16, State 1, Line 1
OLE DB provider 'MSDASQL' reported an error.

Any idea what this error means?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-01-2008, 01:15 PM
AlterEgo
 
Posts: n/a
Default Re: Stored Procedure querying another database

Marek,

In order to use a linked server, the server has to be capable of a four part
namespace. Your example was only showing a three part namespace.

You were using:
LINKEDSERVERNAME.SCHEMA.TABLE

You need to be able to specify:
LINKEDSERVERNAME.DATABASE.SCHEMA.TABLE

Do the ODBC drivers and databases you are using support a four-part name. If
they don't, then you will have to use OPENROWSET.

I don't know about SQL 2005, but in SQL 2K you can not inherit any part of
the namespace if the database is on a different server. The following won't
work:

LINKEDSERVERNAME.DATABASE..TABLE

-- Bill

<mkarbarz@gmail.com> wrote in message
news:1170801310.273492.21720@m58g2000cwm.googlegro ups.com...
> On Feb 6, 5:09 pm, "Steve" <morrisz...@hotmail.com> wrote:
>> On Feb 6, 1:25 pm, "mkarb...@gmail.com" <mkarb...@gmail.com> wrote:
>>
>> > Hello,

>>
>> > I need to come up with a stored procedure that will allow me to read
>> > data from another database. The database I need to read the data from
>> > is a UniData residing on a Unix server. The stored procedure needs to
>> > reside on my sql 2005 server. The task is very simple in Access as we
>> > have ODBC connections set up to the UniData via Informix (or IBM)
>> > UniData ODBC drivers. I can easily combine my UniData and Sql Server
>> > tables from within access. However, I can't seem to find a way to
>> > replicate the same behavior in MS SQL Stored Procedure without the use
>> > of Access. Is that even possible?

>>
>> > Thanks,

>>
>> > Marek

>>
>> Linked server or OPENROWSET
>> In SQL Server 2005 Books Online see the topic: Distributed Queries

>
> I started playing around with the linked server and I got it to the
> point where I can see the tables from UniData, but when I try to query
> it using LINKEDSERVERNAME...TABLE I get 'Invalid schema or catalog
> specified for provider 'MSDASQL'." error. When I try to specify
> schema using LINKEDSERVERNAME.SCHEMA.TABLE I get 'Invalid object name
> LINKEDSERVERNAME.SCHEMA.TABLE'; do you know why these errors occur
> and how to get around them?
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-01-2008, 01:15 PM
mkarbarz@gmail.com
 
Posts: n/a
Default Re: Stored Procedure querying another database

On Feb 6, 6:18 pm, "AlterEgo" <altereg...@dslextreme.com> wrote:
> Marek,
>
> In order to use a linked server, the server has to be capable of a four part
> namespace. Your example was only showing a three part namespace.
>
> You were using:
> LINKEDSERVERNAME.SCHEMA.TABLE
>
> You need to be able to specify:
> LINKEDSERVERNAME.DATABASE.SCHEMA.TABLE
>
> Do the ODBC drivers and databases you are using support a four-part name. If
> they don't, then you will have to use OPENROWSET.
>
> I don't know about SQL 2005, but in SQL 2K you can not inherit any part of
> the namespace if the database is on a different server. The following won't
> work:
>
> LINKEDSERVERNAME.DATABASE..TABLE
>
> -- Bill
>
> <mkarb...@gmail.com> wrote in message
>
> news:1170801310.273492.21720@m58g2000cwm.googlegro ups.com...
>
>
>
> > On Feb 6, 5:09 pm, "Steve" <morrisz...@hotmail.com> wrote:
> >> On Feb 6, 1:25 pm, "mkarb...@gmail.com" <mkarb...@gmail.com> wrote:

>
> >> > Hello,

>
> >> > I need to come up with a stored procedure that will allow me to read
> >> > data from another database. The database I need to read the data from
> >> > is a UniData residing on a Unix server. The stored procedure needs to
> >> > reside on my sql 2005 server. The task is very simple in Access as we
> >> > have ODBC connections set up to the UniData via Informix (or IBM)
> >> > UniData ODBC drivers. I can easily combine my UniData and Sql Server
> >> > tables from within access. However, I can't seem to find a way to
> >> > replicate the same behavior in MS SQL Stored Procedure without the use
> >> > of Access. Is that even possible?

>
> >> > Thanks,

>
> >> > Marek

>
> >> Linked server or OPENROWSET
> >> In SQL Server 2005 Books Online see the topic: Distributed Queries

>
> > I started playing around with the linked server and I got it to the
> > point where I can see the tables from UniData, but when I try to query
> > it using LINKEDSERVERNAME...TABLE I get 'Invalid schema or catalog
> > specified for provider 'MSDASQL'." error. When I try to specify
> > schema using LINKEDSERVERNAME.SCHEMA.TABLE I get 'Invalid object name
> > LINKEDSERVERNAME.SCHEMA.TABLE'; do you know why these errors occur
> > and how to get around them?- Hide quoted text -

>
> - Show quoted text -


thanks for all your help; indeed with OPENROWSET I was able to get
the query working with no problems (or at least the problems I'm
having are not related to the tables, rather with Error converting
data type DBTYPE_DBDATE to datetime, but that's a topic for another
thread if I can't figure it out)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 03-01-2008, 01:15 PM
AlterEgo
 
Posts: n/a
Default Re: Stored Procedure querying another database

marek,

You can't use inherited names. In other words, don't put two periods
together. See my other post.

-- Bill

<mkarbarz@gmail.com> wrote in message
news:1170804277.261564.3540@v45g2000cwv.googlegrou ps.com...
> On Feb 6, 6:07 pm, Erland Sommarskog <esq...@sommarskog.se> wrote:
>> mkarb...@gmail.com (mkarb...@gmail.com) writes:
>> > I started playing around with the linked server and I got it to the
>> > point where I can see the tables from UniData, but when I try to query
>> > it using LINKEDSERVERNAME...TABLE I get 'Invalid schema or catalog
>> > specified for provider 'MSDASQL'." error. When I try to specify
>> > schema using LINKEDSERVERNAME.SCHEMA.TABLE I get 'Invalid object name
>> > LINKEDSERVERNAME.SCHEMA.TABLE'; do you know why these errors occur
>> > and how to get around them?

>>
>> To refer to an object on a remote server, you must use four-part
>> notation: server.catalog.schema.table. So that's why
>> INKEDSERVERNAME.SCHEMA.TABLE does not work.
>>
>> Unfortunately, I have no idea what will work, since I've never heard of
>> Unidata before.
>>
>> --
>> Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se
>>
>> Books Online for SQL Server 2005
>> athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
>> Books Online for SQL Server 2000
>> athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

>
> I started using the 4 part query and I guess I got a step further;
> now I'm getting a different error:
>
> the query is: SELECT * FROM AVLIVE..ii.SODET_NF
>
> the error:
> [OLE/DB provider returned message: Unspecified error]
> [OLE/DB provider returned message: [Ardent][UniData ODBC
> Driver]Invalid column number.]
> OLE DB error trace [OLE/DB Provider 'MSDASQL'
> IDBSchemaRowset::GetRowset returned 0x80004005: ].
> Msg 7399, Level 16, State 1, Line 1
> OLE DB provider 'MSDASQL' reported an error.
>
> Any idea what this error means?
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:57 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com