Showing posts with label queries. Show all posts
Showing posts with label queries. Show all posts

Wednesday, March 28, 2012

Ok, here's a tough one:

I have two nearly identical queries with VERY different execution plans and execution times. This is on SQL 2000.

--QUERY 1:

select A

from tb_1

where B = 'SomeUnicodeString'

and C = {guid'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'}

--QUERY 2:

declare @.B nvarchar(50), @.C UniqueIdentifier

select @.B = 'SomeUnicodeString', @.C = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

Select A

from tb_1

where B = @.B

and C = @.C

Indexes on tb_1

are ndx1 non-unique non-clustered (A,B)

and ndx2 non-unique non-clustered (B,C)

First query takes about 6 seconds. Second query runs in under 1/2 second.

Thoughts anyone?

In the first you might need to make SomeUnicodeString into an Unicode string by changing it to:

B = N'SomeUnicodeString'

This could be the difference, but you really need to look at the plan to know. In query analyzer, look in the query menu and run the queries with the include actual plans option. It should be showing in the plan.

It could be a cached plan issue. Consider flushing the procedure cache with DBCC FREEPROCCACHE and see if that helps too.

|||

Those two queries will be treated different by the query optimizer. SQL Server will try to parameterize the first one, if is not possible, then it will use the constants as they appear in the statement. The query optimizer probably will use the statistics from the histogram in the second index, to estimate the rows matching the filter. For the second one, it will probably use the density of the columns (B, C) from the second index, to estimate the rows matching the filter, and not the histogram, because the processor will not use the variables to analize the statistics.

Can you post both execution plans and the "All density" block from the result of "dbcc show_statistics (tb_1, ndx2)"?

If you want to parameterize the statement, use sp_executesql.

declare @.sql nvarchar(4000)

declare @.B nvarchar(50), @.C UniqueIdentifier

set @.B = N'SomeUnicodeString'

set @.C = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

set @.sql = N'Select A from tb_1 where B = @.B and C = @.C'

exec sp_executesql @.sql, N'@.B nvarchar(50), @.C UniqueIdentifier', @.B, @.C

go

AMB

Wednesday, March 21, 2012

Odd syntax error with shape queries SQL2000/Win2003

Hi,

I am running SQL Server 2000 SP3 on Windows Server 2003 and since recently
have a strange problem executing shape queries from COM+ components using
ADO.

Until 4 days ago, they worked, then from one moment to the next (I must have
changed something, but I have no clue what other than restoring a 1.2 GB
database) they started failing with this error:

Microsoft OLE DB Provider for SQL Server error '80040e14'
Syntax error or access violation

I have no problem executing non-shape queries, it is just the shape queries
that fail.

Any clues what may have gone wrong? Or how I can fix it?

Cheers,
Rsa Myh> Microsoft OLE DB Provider for SQL Server error '80040e14'
> Syntax error or access violation

And apparently this had nothing to do with Win2003 or SQL Server or any
software at all... Just with a mistake in a setting of my own software...
The datasource string for the shape data source was invalid....

I'm hanging my head in shame..

Monday, March 12, 2012

ODBC Virtual Driver

Hi,
I have the following requirement :

I need to have a way to intercept the SQL queries from an application written in VB and using a ODBC driver and modify the SQL queries before it goes through the ODBC driver and then to the database. This I need to do without modifying the original application.

The solution I have in mind is to write a ODBC virtual driver and configure my application to use my virtual ODBC driver. The ODBC virtual driver in turn will use the actual ODBC driver to the database. The virtual driver will basically intercept the SQL queries, modify it and then give it to the real ODBC driver.

My question is

1. Is this a feasible solution?
2. What should I do in order to implement the vitrtual ODBC driver.
3. Any pointer will be appreciated.

Thanks
Jake.NEver heard of virtual odbc driver, but you may find some information from http://www.microsoft.com site.|||Hi,
What I meant by Virtual driver is basically a ODBC proxy which can sit between my application and the ODBC driver and intercept the SQL queries.

Thanks
Jake

Originally posted by Satya
NEver heard of virtual odbc driver, but you may find some information from http://www.microsoft.com site.|||I'm working from memory here, but I think an ODBC Proxy something like you are describing is included as a VC project in the ODBC Driver SDK.

-PatP

Saturday, February 25, 2012

ODBC Program & Heterogeneous queries problem

Best All,

What I am doing is following:
1. I created a stored procedure "testit" which select records from another data source in another SQL Server, like:

------------
SET ANSI_NULLS ON
SET ANSI_WARNINGS ON
go

create procedure testit
as begin
select * from [AnotherSQLServer].bugtest.dbo.mssent
end

grant execute on testit to public
------------

2. I can execute this stored procedure in SQL Query Analyser with success.

3. BUT: now I write a ODBC program trying to call this stored procedure, then it give me following "famous" error:
42000 [Microsoft][ODBC SQL Server Driver][SQL Server]Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options and then reissue your query.

The ODBC program looks like this:
--------
strcpy((char *) sqltext, "{call testit}");
rc = SQLPrepare(hstmt, (unsigned char *) sqltext, SQL_NTS);
rc = SQLExecute(hstmt);
--------

My Question:
1. Does ODBC API support Heterogeneous queries ?
2. If well, how to solve above problem?

Thanks a lot,

MelThe solution can be found here:

http://dbforums.com/t905850.html

use some thing like this (before calling SQLConnect() ):
SQLSetConnectAttr( hdbc,SQL_COPT_SS_ANSI_NPW,(void *) SQL_AD_ON, 0);

odbc problems with Linked server in sql 2005

Hi guys,

I've a Linked server en sql 2000 with oledb provider for odbc drivers (Progress software) to do some queries, and works fine, I m trying to do the same in sql 2005, i set up exactly as i do in sql 2000 but when I try to view the tables: there are nothing the list is missing and obviosly when i try to query, I got errors:

OLE DB provider "MSDASQL" for linked server "test" returned message "[DataDirect-Technologies][ODBC PROGRESS driver]Driver's SQLSetConnectAttr failed.".

OLE DB provider "MSDASQL" for linked server "test" returned message "[DataDirect-Technologies][ODBC PROGRESS driver][PROGRESS]Access denied(Authorisation failed)".

OLE DB provider "MSDASQL" for linked server "test" returned message "[DataDirect-Technologies][ODBC PROGRESS

ex:

works perfectly in sql 2000, not in 2005

SELECT * FROM OPENQUERY (MY_LINKED_SERVER, 'SELECT * FROM AFN_cotizaseguro_rmt')

some body knows if i have to set up additional stuff in sql 2005?

Hi

This seems to be a discussion on ProgressTalk that refers to your problem:

http://www.progresstalk.com/showthread.php?t=103352

If the connection works in the ODBC administrator Test Connection then they seem to suggest checking the security context setting in the security page of the linked servers settings in SQL Management studio.

I hope this is some use to you.

|||

Thank u Dhericean, you really help me, now I 'm working with my linked servers in sql 2005, it was just a click in the security, awesome !!!

Regards

ODBC Permissions from Custom Data Processing Extension

Hi
I am trying to create a custom data processing extension that queries a Sybase database (ie odbc), then on the basis of this data queries a SQL Server database. However, when I get to querying the Sybase database, the method instantly crashed with a SecurityException "Request Failed." exception being thrown. I have so far being guessing that this is due to Permissions.
I have tried to create a OdbcPermission Permission Set which I have assigned to the relevant code group, and also have put a OdbcPermission attribute at the start of the method which is to access the Sybase database, but to no avail.
Does anybody have any idea what I can do to resolve this problem?
Thanks
Jan
*****************************************
* This message was posted via http://www.sqlmonster.com
*
* Report spam or abuse by clicking the following URL:
* http://www.sqlmonster.com/Uwe/Abuse.aspx?aid=72424bb9b1394d278da3c0fb33e5c352
*****************************************Almost certain that it is a Permissions issue now, as I set it to FullTrust and it made a connection to the Sybase database.
Can anybody tell me how to set up the permissions for connecting to an ODBC database for use in a custom assembly?
Would be much appreciated!
*****************************************
* A copy of the whole thread can be found at:
* http://www.sqlmonster.com/Uwe/Forum.aspx/sql-server-reporting/4587
*
* Report spam or abuse by clicking the following URL:
* http://www.sqlmonster.com/Uwe/Abuse.aspx?aid=b41e9858e9da41d88067b4f8fb5cabe6
*****************************************|||Hi Jan,
the ODBCPermission class is intended for future use when the .NET Framework
Data Provider for ODBC is enabled for partial trust scenarios. The .NET
Framework Data Provider for ODBC currently requires FullTrust permission. At
present, using the OdbcPermission class has no effect. You may also want to
check this MSDN article:
Code access security and ADO.NET
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcodeaccesssecurityadonet.asp
HTH, Robert
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jan Bodey via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:b41e9858e9da41d88067b4f8fb5cabe6@.SQLMonster.com...
> Almost certain that it is a Permissions issue now, as I set it to
FullTrust and it made a connection to the Sybase database.
> Can anybody tell me how to set up the permissions for connecting to an
ODBC database for use in a custom assembly?
> Would be much appreciated!
> *****************************************
> * A copy of the whole thread can be found at:
> * http://www.sqlmonster.com/Uwe/Forum.aspx/sql-server-reporting/4587
> *
> * Report spam or abuse by clicking the following URL:
> *
http://www.sqlmonster.com/Uwe/Abuse.aspx?aid=b41e9858e9da41d88067b4f8fb5cabe6
> *****************************************