Monday, February 20, 2012
ODBC In Stored Procedure
I'm trying to get the column names from a table to which I'm connected
through OBDC. I don't want to use linked server. I get my data with
Openrowset.
I found the SQLDescribeCol and SQLColumns ODBC functions.
Can anybody tell me how to use those functions in a SQL Server stored
procedure?
Thanks a lotHi Pumkin,
should work as follows
SELECT colId, name,
FROM dbo.sysObjects
WHERE Id = OBJECT_ID('YourTableName')
ORDER BY ColId
HTH ;-)
Gru, Uwe Ricken
MCP for SQL Server 2000 Database Implementation
GNS GmbH, Frankfurt am Main
http://www.gns-online.de
http://www.memberadmin.de
http://www.conferenceadmin.de
________________________________________
____________
dbdev: http://www.dbdev.org
APP: http://www.AccessProfiPool.de
FAQ: http://www.donkarl.com/AccessFAQ.htm|||Hey,
I should explain myself better... I need to get the column names of a
table given as parameter. There is COLUMN_NAME from INFORMATION_SCHEMA
for SQL Server. The problem is that my table is not on my server and is
not a SQL Server table either. I need to access it through ODBC.
Can anybody help? Thanks|||Pumkin wrote:
> Hey,
> I should explain myself better... I need to get the column names of a
> table given as parameter. There is COLUMN_NAME from INFORMATION_SCHEMA
> for SQL Server. The problem is that my table is not on my server and
> is not a SQL Server table either. I need to access it through ODBC.
> Can anybody help? Thanks
It is not possible to use the ODBC functions you mentioned from a stored
procedure which can only run queries via openrowset.
If the table is in a relational database, then it should be possible to run
a query against that database to get the column names. Without more specific
information, it is impossible to go into details. Maybe you should try a
newsgroup devoted to the rdbms you are linking to.
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.|||Hy Bob,
Thanks for the reply. The database that I am connecting to in not
relational. But I found something now...
It works if I do "select * from table where 1=2"
But I was looking for something more dynamically build.|||Pumkin wrote:
> Hy Bob,
> Thanks for the reply. The database that I am connecting to in not
> relational. But I found something now...
> It works if I do "select * from table where 1=2"
> But I was looking for something more dynamically build.
I'm not sure how that helps you: your t-sql code is not going to be able to
read those column names. I was thinking that you needed your code to somehow
use those column names for something.
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
ODBC in Stored Procedure
I'm trying to get the column names from a table to which I'm connected
through OBDC. I don't want to use linked server. I get my data with
Openrowset.
I found the SQLDescribeCol and SQLColumns ODBC functions.
Can anybody tell me how to use those functions in a SQL Server stored
procedure?
Thanks a lotPumkin (PopClaudia@.gmail.com) writes:
> I'm trying to get the column names from a table to which I'm connected
> through OBDC. I don't want to use linked server. I get my data with
> Openrowset.
> I found the SQLDescribeCol and SQLColumns ODBC functions.
> Can anybody tell me how to use those functions in a SQL Server stored
> procedure?
You can't. Well, you could write an extended stored procedure or an
OLE object that you could call from a stored procedure, and that would
use these functions.
However, it would be more straight forward to query the system catalog
on the remote server directly.
What exactly are you trying to achieve?
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx
ODBC failing to connect
am trying to setup the OBDC on the ISA server and it is failing each time.
It cannot reach the server. Every other computer in the domain can access
the SQL server via OBDC. So what am I missing to do that on the ISA server.
I am running ISA 2006 Enterprise, and have set the system policy to use SQL
for logging. Plus I have a access rule that allows SQL through ISA. Anyone
know what I missed?
TCP/IP is set up as dynamic, and I can ping the SQL Server.
The following is the failure I get from ODBC:
Connection failed:
SQLState: '01000'
SQL Server Error: 10065
[Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]ConnectionOpen
(Connect()).
Connection Failed:
SQLState: '08001'
SQL Server Error: 17
[Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]SQL Server does not exist
or access denied.
Thanks,
Michael R. Mastro II
It can be a lot of different things. Enable login auditing
or run profiler to see if it's actually connecting on the
SQL Server end. It just makes troubleshooting easier.
If it's a named instance, make sure you are specifying the
instance name.
You'd also want to check your ports and protocols - one way
to check is look in the SQL Server error log from when it
started up to determine what ports and protocols SQL Server
is listening on.
From the ISA server, try to telnet to the port SQL Server is
listening on. Make sure the client end (ISA) is using the
same port.
Make sure SQL Server is listening on the correct protocols
as well. Make sure you have TCP/IP enabled.
And then run through the following article:
Potential causes of the "SQL Server does not exist or access
denied" error message
http://support.microsoft.com/?id=328306
-Sue
On Tue, 23 Jan 2007 10:03:10 -0500, "Michael Mastro"
<MikeRM2XXX@.worldnet.att.net> wrote:
>Ok here is the problem. I am trying to set up logging on SQL 2005. Now I
>am trying to setup the OBDC on the ISA server and it is failing each time.
>It cannot reach the server. Every other computer in the domain can access
>the SQL server via OBDC. So what am I missing to do that on the ISA server.
>I am running ISA 2006 Enterprise, and have set the system policy to use SQL
>for logging. Plus I have a access rule that allows SQL through ISA. Anyone
>know what I missed?
>TCP/IP is set up as dynamic, and I can ping the SQL Server.
>The following is the failure I get from ODBC:
>Connection failed:
>SQLState: '01000'
>SQL Server Error: 10065
>[Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]ConnectionOpen
>(Connect()).
>Connection Failed:
>SQLState: '08001'
>SQL Server Error: 17
>[Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]SQL Server does not exist
>or access denied.
>
>Thanks,
>Michael R. Mastro II
>
|||I tried the following with still no luck.
First off I went into the SQL Server logs and found out that it is listening
in on TCP port 2440, it also mentioned 2441.
I then went to the ISA server and created protocol that allows inbound and
outbound connections on 1433, 2440, and 2441. I created an access rule that
allows any of the protected networks and the local host to access the new
protocol I created with the SQL server.
I went back to the SQL server machine, and started up the profiler to run a
trace.
Back to the ISA machine, and opened up telnet and tried to connect to SQL
server machine via 1433, then 2440, then 2441. Each time connect failed. I
also tried a static IP on the ODBC set for 2440. And each time as the same
before.
I looked over the SQL Profiler trace and it does not even show any
connection attempts from the ISA machine.
Pinging and PathPinging show good connections. Plus a looking over the
ports on the SQL server machine show that it is listening on those ports.
Still scratching my head.
Michael R. Mastro II
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:iejdr215njd7fp0taafif3lcsdb508i420@.4ax.com...
> It can be a lot of different things. Enable login auditing
> or run profiler to see if it's actually connecting on the
> SQL Server end. It just makes troubleshooting easier.
> If it's a named instance, make sure you are specifying the
> instance name.
> You'd also want to check your ports and protocols - one way
> to check is look in the SQL Server error log from when it
> started up to determine what ports and protocols SQL Server
> is listening on.
> From the ISA server, try to telnet to the port SQL Server is
> listening on. Make sure the client end (ISA) is using the
> same port.
> Make sure SQL Server is listening on the correct protocols
> as well. Make sure you have TCP/IP enabled.
> And then run through the following article:
> Potential causes of the "SQL Server does not exist or access
> denied" error message
> http://support.microsoft.com/?id=328306
>
> -Sue
> On Tue, 23 Jan 2007 10:03:10 -0500, "Michael Mastro"
> <MikeRM2XXX@.worldnet.att.net> wrote:
>
|||Well at least it's narrowed down. Check the logs on your ISA
server. It looks like it's still being blocked there.
-Sue
On Thu, 25 Jan 2007 10:35:04 -0500, "Michael Mastro"
<MikeRM2XXX@.worldnet.att.net> wrote:
>I tried the following with still no luck.
>First off I went into the SQL Server logs and found out that it is listening
>in on TCP port 2440, it also mentioned 2441.
>I then went to the ISA server and created protocol that allows inbound and
>outbound connections on 1433, 2440, and 2441. I created an access rule that
>allows any of the protected networks and the local host to access the new
>protocol I created with the SQL server.
>I went back to the SQL server machine, and started up the profiler to run a
>trace.
>Back to the ISA machine, and opened up telnet and tried to connect to SQL
>server machine via 1433, then 2440, then 2441. Each time connect failed. I
>also tried a static IP on the ODBC set for 2440. And each time as the same
>before.
>I looked over the SQL Profiler trace and it does not even show any
>connection attempts from the ISA machine.
>Pinging and PathPinging show good connections. Plus a looking over the
>ports on the SQL server machine show that it is listening on those ports.
>Still scratching my head.
>Michael R. Mastro II
>"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
>news:iejdr215njd7fp0taafif3lcsdb508i420@.4ax.com.. .
>
|||Well looking at the Firewall logs I can see the it is opening the port then
2 seconds later terminating with a 0x80074E21. Still unable to figure a way
around this one.
Michael R. Mastro II
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:0e3jr2dffad96n056htlmnpkrubqdvr49s@.4ax.com...
> Well at least it's narrowed down. Check the logs on your ISA
> server. It looks like it's still being blocked there.
> -Sue
> On Thu, 25 Jan 2007 10:35:04 -0500, "Michael Mastro"
> <MikeRM2XXX@.worldnet.att.net> wrote:
>