.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

Slow performance with SQL Server 2005 executing parameterized queries with LIKE and an aggregate com

Posted By:      Posted Date: October 13, 2010    Points: 0   Category :Sql Server
 

We have a slow-performing query and, after some analysis, have narrowed the cause down to using parametrized queries in conjunction with LIKE and aggregate comparisons used in the WHERE clause.  If we use a non-parametrized query (but keep the WHERE clause the same) the query performs much faster and, in fact, executes a different plan.  Using OPTIMIZE FOR UNKNOWN is not an option for us as we are using SQL Server 2005.  Obviously, we'd like to use parametrized queries to prevent SQL injection but the slow perf is unacceptable.  We need the LIKE to support wildcard scenarios.  If we need to we'll use dynamic SQL (scrubbed as much as we can) in lieu of parametrized queries.  We're wondering, however, is there another option that would give us the perf without sacrificing safety?  I can provide a sample database, query, plans, etc. if necessary...I'm assuming SQL Server generates a less efficient plan with the parametrized query as it can't make any assumptions about the parameter values...

Mike Bouck




View Complete Post


More Related Resource Links

Slow performance with SQL Server 2005 executing parameterized queries with LIKE and an aggregate com

  

We have a slow-performing query and, after some analysis, have narrowed the cause down to using parametrized queries in conjunction with LIKE and aggregate comparisons used in the WHERE clause.  If we use a non-parametrized query (but keep the WHERE clause the same) the query performs much faster and, in fact, executes a different plan.  Using OPTIMIZE FOR UNKNOWN is not an option for us as we are using SQL Server 2005.  Obviously, we'd like to use parametrized queries to prevent SQL injection but the slow perf is unacceptable.  We need the LIKE to support wildcard scenarios.  If we need to we'll use dynamic SQL (scrubbed as much as we can) in lieu of parametrized queries.  We're wondering, however, is there another option that would give us the perf without sacrificing safety?  I can provide a sample database, query, plans, etc. if necessary...I'm assuming SQL Server generates a less efficient plan with the parametrized query as it can't make any assumptions about the parameter values...

Mike Bouck


SQL Server 2005 Performance Dashboard Reports user context

  
HI, We are planning on installing the Dashboard reports. But we'd like to know if the Dashboard is run under admin user or the login user who runs the Dashboard reports? Thanks! Kong

Slow performance when searching in "any part of field" of a SQL Server database using a Microsoft Ac

  
We have just migrated our back end database from Access to MS SQL Server 2008 R2. We have noticed better performance on our searches - unless we select to search in "any part of field" in Access (with Access' built-in search function - we use a mix of Access 2003 and 2007). This takes nearly 20 seconds to find the result, whereas before the migration it was taking 5-7 seconds (compared to instant results we now experience when searching for whole fields). The main fields we search are not large - usually just two words. Obviously it is better to search for a whole or start of a field, but this is not always possible. The contractor that assisted us in this project has told us that this "is just the way SQL works with Access". Is this really true? I find it hard to believe two MS products would have such a big issue between them. I presumed using SQL with an Access front end would be a common setup, which is why I thought this must be a problem with our setup. Is there any way to fix this speed issue?

SQL Server 2005 Analysis Services - Performance of Excel Pivot Tables

  
Hi, I've several cubes available for several users within my organization. I've the SQL Server 2005 and the Analysis Services running on the same machine but it has 30Gb of RAM, 8 processors and a quick enouth disk. The problems is that i've some automatic processes that "build" some excel reports and the users use pivot tables with olap connections to the cubes regularly. I've noticed that the excel "locks" when the user is drilling down the data and the server has only one processor (there are 8...) at 100%... Is there a way to make the analysis services use the maximum processing capacity that is available? The users are complaining about the slowness of the cubes... Thanks in advance Hugo

XMLDML insert is dog slow for real inserts in SQL Server 2005

  
I put together a little sample after noticing my XML solution was taking more than three seconds every time I inserted something over 20 records with a reasonable number of attributes. XML updating is apparently not ready for production code in 2005. This is faster in SQL Server 2008, and might work for some applications, but you'd actually write the code a little differently there. In any case, it's far slower than writing out the string yourself. Anyhow, if anyone asks you why you're not using XML.modify('insert in SQL Server 2005, you can run this for them.  DECLARE @now DATETIME, @then DATETIME, @elapsed INT, @now_disp NCHAR(24); SET @now = GETDATE(); SET @now_disp = CONVERT(NCHAR(24), @now, 126); RAISERROR('starting timer at %s', 11, 1, @now_disp) WITH NOWAIT; DECLARE @root XML, @insert NVARCHAR(MAX), @counter INT, @child XML, @att NCHAR(3), @attdex tinyint; SET @root = '<root/>'; SET @counter = 24; WHILE @counter < 26 BEGIN SET @counter = @counter + 1 SET @child = CAST('<child/>' AS xml) SET @attdex = 0; WHILE @attdex < @counter BEGIN SET @attdex = @attdex + 1; SET @att = CHAR(96 + @attdex) + 'ow'; SET @insert = 'SET @child.modify(''insert attribute ' + @att + ' {"value"} into (/child)[1]'');'; EXEC sys.sp_executesql @insert, N'@child xml OUT', @child

Data Transfer in C# slow when targeting SQL Server 2005 using SQL Server SMO version 10 (distributed

  

 

Hello everyone,

I have a strange issue regarding SQL Server SMO Transfer. I am using the Transfer class to create a copy of a database. I will explain the different cases I have tried so far and maybe someone can help me figure out what's going on.

First case

I run my C# code from an assembly that references version 9.0.242.0 of SMO assemblies that are in my GAC

  • Microsoft.SqlServer.ConnectionInfo
  • Microsoft.SqlServer.Smo
  • Microsoft.SqlServer.SqlEnum

If I target a database hosted on a Sql Server 2005 database engine, it works perfectly and fast.

But of course, as soon as I try to target a Sql Server 2008 database engine, it complains that it is not compatible. No surprise there.

 

Second case

I run the exact same C# code from an assembly that references version 10.0.0.0 of SMO assemblies that are also present in my GAC

  • Microsoft.SqlServer.ConnectionInfo
  • Microsoft.SqlServer.Management.Sdk.Sfc
  • Microsoft.SqlServer.Smo
  • Microsoft.SqlServer.Smo.Extended
  • Microsoft.SqlServer.SqlEnum

If I target a database hosted on a Sql Server 2008 database engine, it works perfectly and fast.

However, if I try to target the sam

Data Transfer in C# slow when targeting SQL Server 2005 using SQL Server SMO version 10 (distributed

  

 

Hello everyone,

I have a strange issue regarding SQL Server SMO Transfer. I am using the Transfer class to create a copy of a database. I will explain the different cases I have tried so far and maybe someone can help me figure out what's going on.

First case

I run my C# code from an assembly that references version 9.0.242.0 of SMO assemblies that are in my GAC

  • Microsoft.SqlServer.ConnectionInfo
  • Microsoft.SqlServer.Smo
  • Microsoft.SqlServer.SqlEnum

If I target a database hosted on a Sql Server 2005 database engine, it works perfectly and fast.

But of course, as soon as I try to target a Sql Server 2008 database engine, it complains that it is not compatible. No surprise there.

 

Second case

I run the exact same C# code from an assembly that references version 10.0.0.0 of SMO assemblies that are also present in my GAC

  • Microsoft.SqlServer.ConnectionInfo
  • Microsoft.SqlServer.Management.Sdk.Sfc
  • Microsoft.SqlServer.Smo
  • Microsoft.SqlServer.Smo.Extended
  • Microsoft.SqlServer.SqlEnum

If I target a database hosted on a Sql Server 2008 database engine, it works perfectly and fast.

However, if I try to target the sam

Slow sql-server after upgrade from SQL-Server 2005 x64 standard to SQL-Server 2008 R2 x64 enterprise

  

We moved our databases to new hardware today (using copy database wizard)

 

The new hardware should be better than the old one.

We went from 28 GB ram to 128 GB.

We went from 16 cores to 32 cores (with even more cache etc.). We also moved from external SAN with 40 disks to intern disks (8 Samsung SS805 100gb ssd slc)

                             According to our own metrics we could get twice the IO using IO m

Performance Counter Transactions/Sec in SQL Server 2005

  

hi,

Which factor impacts the Transactions/Sec in SQLServer 2005. What could be the reason to get less Transactions/Sec.

After some code changes in the stored procedure, the Transactions/Sec rate has come down.

Thanks,

Jyothi.


SQL Server 2005 store procedure performance issue

  

We are calling store procedure from vb.net client following are the observation.

1) sqlserver 2005  takes huge amount of time (more than 1 hour) to execute procedure. The procedure has select statement using join statement. (Generally this procedure executes and populate data in 5 seconds when it is called from .net client.)

2) If same procedure is executed from sql server management studio, procedure executes and populate data in 5 seconds (works as per expectation)

3) If we recompile procedure (i.e. open procedure in alter mode in management studio and click on execute button) ,  the procedure executes and populate data as per expectation.

4) This is intermittent issue on production machine. Most of the time procedure is executed and populate data as per expectation when called from vb.net client. But it does not give expected outout in some scenario. The frequency for occurring the issue is  once in 15 days and there is no pattern in which the issue is occurring.

 

Can any one help to resolve the issue.

 

Thanks in advance!!!

 

 

 


SQL Server 2005 Replication - Replicated Databse Performance Issue

  

Hello,

 

I am struggling to work out a very frustrating replication issue and wondered if anyone could help me.

Here is my situation.

 

I have a virtual machine with 16gb RAM and 4 quad core 3Ghz processors and 250gb disk. This has Windows Server 2008 64 bit installed.

The machine has a SQL Server 2005 64 bit instance installed with SP3.

I have setup a publication on this SQL Server called pub1 , this publication publishes all tables/sp's /views and UDF's . I have set the article properties for the published tables as below.

- Copy Check Constraints = True

- Copy Clustered Index = True

- Copy Non Clustered Index = True

- Copy Default Value Spec = True

- Copy Collation = True

- Copy Insert, Update and Delete = True

- Copy unique key contraints = True

- Copy XML Indexes = True

Every other setting is set to false.

I have created a subscription to pub1 within the same SQL Server instance. The database has replicated everything I require without an issue.

If I run a query against the databse that I have published, it returns the query in less than 10 secs. If I run the same query against the subscription DB then this query takes over 30 mins to return.

I thought this was an issue with the indexes not replicating. From what I have selecte

SQL SERVER 2005 Performance

  

We have SQL SERVER 2005 SP3 Enterprise 32-bit running on a windows server 2003 Enterprise 32-bit with 32GB of RAM and 8 dual core processors. Our CPU, RAM, and I/O are always through the roof and the application is always running slow. We use AWE for buffer cache the maximum memory is 28GB, the PAGEIOLATCH_SH is always high and the procedure cache is always around 700mB. Durring production hours we have over 6000 connections to sql server (500 users). What is wrong here? Please help. Thank you.

 


Executing XML query from SQL 2005 pointing to SQL 2000 server

  
Occurs with root command.
Executed as user: DOMAIN\SERVER01. Error Code: 0  Error Source= ADODB.Command  Error Description: Item cannot be found in the collection corresponding to the requested name or ordinal.    Error on Line 18.  The step failed.
 
Executed as user: DOMAIN\SERVER01. Error Code: 0  Error Source= Microsoft OLE DB Provider for SQL Server  Error Description: Line 1: Incorrect syntax near 'ROOT'.    Error on Line 20.  The step failed.
CODE:
Dim oCmd, sSQL, oDom
   
   Set oDom = CreateObject("Microsoft.XMLDOM")
  
   Set oCmd = CreateObject("ADODB.Command")
  oCmd.ActiveConnection ="Driver={SQL Native Client};Database=Validation;Server=server1;Uid=sa;Pwd=;"
  
   sSQL = "<?xml version=""1.0"" ?>"
   sSQL = sSQL &

SQL 2005 Linked Server to Oracle 10g - Very Slow

  

Hi,

 

Anyone have some recommendations for a slow linked server from SQL 2005 to Oracle 10g?

 

Here is the situation.  We have an application that runs on SQL 2005 - Win 2003, and in certain forms it makes calls to an Oracle 10g database running on Sun Unix.  This database was upgraded from SQL 2000 Win 2000.  We have a test system mirroring production and have the same problems.

 

- All indexes are being used.

- Server configuration is correct.

- Changed the Oracle 10g driver from the main driver to the Instant Client - much smaller but same result.

- Read an old post about same issue but the person was connecting to 8i so they were using a different driver.

- I have been running profiler and the problem seems to be a remote scan on the Oracle side.  We are using the OPENQUERY call from the application.

- All other parts of the app are running fine, just the outside connection.

- We are using the Windows Firewall and all DCOM components are set as Microsoft recommends.  I don't think this is an issue because the test server is not using Windows Firewall and we have the same issue on that server.

 

Any suggestions would be greatly appreciated.  I have run into the wall :-)

 

thanks

Matt


SQL Server 2005 Try and Catch Exception Handling

  
I'm pretty excited to see that there is some real error handling for T-SQL code in SQL Server 2005. It's pretty painful to have your wonderfully architected .NET solution tainted by less-than-VBScript error handling for stored procedures in the database. The big difference being the addition of TRY..CATCH blocks. Let's take a look:

SQL Server Performance

  
Improving .NET Application Performance and Scalability
SQL: Scale Up vs. Scale Out
Schema
Queries
Indexes
Transactions
Stored Procedures
Execution Plans
SQL XML
Tuning
Testing
Monitoring
Deployment Considerations

sql server 2000 vs 2005

  

i would like to ask what the difference between sql server 2000 and 2005 


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend