Showing posts with label failing. Show all posts
Showing posts with label failing. Show all posts

Saturday, February 25, 2012

ODBC Returning success but actually failing (SQL Native)

I'm talking to SQL 2005 using the SQL Native client in ODBC:

Here's what I'm doing:

1) SQLPrepare () -- Prepair an insert stmt
2) SQLBindParameter() -- Binding the parameter
3) Set the Parameter to a value
4) SQLExecute() -- Execute the statment
5) Set the Parameter to a different value
6) SQLExecute() -- Execute the statment

Both calls to SQLExecute() return SUCCESS_WITH_INFO.

The problem is that only the 1st SQLExecute() ever makes it to the database. The second SQLExecute() never gets executed at the database AND it returns a success condition.

When I check what the info is, it's "[Microsoft][SQL Native Client]Fractional truncation". Not an issue since I'm setting a datetime value in the database and I don't care about the milliseconds.

Here's the problems with this:

1) SQLExecute() return success yet it does not execute the statement. How can I tell if the statement fails if SQLExecute() always return success?

2) Why does a previous success with info cause all future executes to not happen?

So, is there a way to tell odbc to ignore the info and allow the next execute to run?

Thanks for any help,

Scott

Could you send some sample code that demonstrates the problem please?

How do you know the 2nd execute is not making it to the server? How you looked at a profiler trace or are you just examining the database?

|||

I'm use SQL Server profiler to determine the second SQLExecute is never making it to the database.

I've done some more testing on this and here's what I have found:

1) The problem exists with the "SQL Native Client" ODBC driver. The "SQL Server" does not have this problem. Switching to the "SQL Server" driver fixes the problem.

2) The problem seems to exist only when using the SQL

Here's how to reproduce the problem:

Step 1: In SQL 2005, create table with a datetime field. Here's the code I used:
CREATE TABLE [dbo].[TestTbl] ( [TestDate] [datetime] NULL )

Step 2: Create an ODBC connection to this table using the SQL Native Client driver. In my example, I called it "TestNative"

Step 3: Here's the VC++ code that uses ODBC to connect to the database and insert data into the TestTbl table:

-- BEGIN CODE BLOCK
CDatabase db;
db.OpenEx ("DSN=TestNative;APP=Test App;WSID=SCOTT1;DATABASE=Test2;Trusted_Connection=Yes", CDatabase::noOdbcDialog);

HSTMT hstmt;
::SQLAllocHandle (SQL_HANDLE_STMT, db.m_hdbc, &hstmt);

LPCTSTR strSQL = ;
::SQLPrepare (hstmt, (SQLCHAR *) "INSERT INTO TestTbl (TestDate) VALUES (?)", SQL_NTS);

SQL_TIMESTAMP_STRUCT sqlTimestamp;
SQLLEN Ind = sizeof (sqlTimestamp);
::SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_TIMESTAMP, SQL_TIMESTAMP, 0, 4, &sqlTimestamp, Ind, &Ind);

sqlTimestamp.year = 2006;
sqlTimestamp.month = 6;
sqlTimestamp.day = 1;
sqlTimestamp.hour = 1;
sqlTimestamp.minute = 1;
sqlTimestamp.second = 1;
sqlTimestamp.fraction = 0;
::SQLExecute (hstmt);

sqlTimestamp.day = 2;
::SQLExecute (hstmt);

::SQLFreeHandle (SQL_HANDLE_STMT, &hstmt);
-- END CODE BLOCK

Using the ODBC "SQL Server" driver, this code inserts 2 records into TestTbl.
Using the ODBC "SQL Native Client" drivre, only 1 record gets inserted.

Running SQL Server profiler to monitor what happens in the database, when the first SQLExecute() executes, a "exec sp_prepexec ..." statement is run on server. This happens with both ODBC drivers.
The problem is that with the second SQLExecute() nothing happens in the database if the "SQL Native Client" driver is used. If the "SQL Server" driver is used, "exec sp_execute 1,''2006-06-02 01:01:00:000''" is run at the server.

|||

I couldn't get the sample code to run as supplied because of an error in SQLBindParameter. You need ColumnSize and DecimalDigits set to 19, 0 or 23, 3. (See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbccolumn_size.asp for details)

Once I'd fixed the problem with SQLBindParameter I got two rows inserted with both SQL Server and SQL Native Client drivers.

I ran my repro as an ODBC v3 app.

If I ran the app as an ODBC v2 app with your settings for SQLBindParameter then I managed to reproduce your problem, but if I ran with 19,0 or 23,3 I got two rows inserted.

So, if you run as an ODBC v3 app (via SQLSetEnvAttr call before connecting) you'll get better diagnostics from SQLBindParameter. Even if not, if you provide correct values for precision and scale on SQLBindParameter the problem will go away.

We'll investigate why the two drivers behave differently.

Monday, February 20, 2012

ODBC failing to connect

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
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:
>