Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
woodz93
Starting Member
9 Posts |
Posted - 2009-02-06 : 23:27:21
|
| I'm new to this site, sorry. My dilemma is that after planning / building a database and populating it with data, we are starting now to invoke queries in .asp pages. It is a SQL 2000 relational database, and some tables run fine (mainly INSERT) using stored procedures invoked by the page. One procedure is really irking my brain, it is an UPDATE on a table that has NO foreign key relationships, it is just a table with a primary key (cust_id).CREATE PROCEDURE inv_UpdateCustodian( @cust_fname varchar(25), @cust_lname varchar(25), @cust_email varchar(50), @cust_address varchar(200), @cust_phone varchar(15), @cust_island varchar(15), @cust_2email varchar(50), @cust_id int) AS UPDATE inventory_custodian SET cust_fname = @cust_fname, cust_lname = @cust_lname, cust_email = @cust_email, cust_address = @cust_address, cust_phone = @cust_phone, cust_island = @cust_island, cust_2email = NULLIF (@cust_2email, '') WHERE cust_id = @cust_idGOI have tried everything from raising timeout via asp command.timeout to inserting NOCONSTRAINT in stored procedure and nothing works - this stored procedure will time out no matter what - unless i remove the primary key declaration. If there is something i missed / did not try, help me out here. Again, apologies if this is in a wrong forum or if it's so easy that i can't figure it out. Thanks in advance! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-07 : 07:47:54
|
| is cust_id your primary key? ALso as Tara suggested, when you run the query in query analyser, analyse the execution plan and see what ere bottleneck steps if its taking large amount of time |
 |
|
|
woodz93
Starting Member
9 Posts |
Posted - 2009-02-07 : 15:13:18
|
| When the update is run in Query Analyzer, it runs < 1 second. I've done checks on blocking, however one thing that i can't put a finger on is when i use Aqua Data Studio and run the Session Manager. I run the query on the asp page and then look at the session manager. I see the process sleeping, and I also find that the query has a 'WAIT RESOURCE' value 'KEY:' followed by some sort of number. The blocked by and blocking values are zero. Hope that helps, thank you all again for your help! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
woodz93
Starting Member
9 Posts |
Posted - 2009-02-08 : 16:06:03
|
| Aqua Data Studio is another database management program similar to Enterprise Manager. If we try diagnosing via Enterprise manager, I do find that under the Management tab, spids under Locks / Process ID correspond to the processes ids that are listed in the Current Activity shot taken upon execution of the queries in question. So you have a lock there? If so, how can i address it? I don't know if it is the application that has issues, it seems simple enough. The application uses an SQLOLEDB connection to connect, the update procedure is invoked by passing the stored procedure name followed by parameters (i.e. "sp_call" x, y, z)? Insert stored procedures work fine too. Thanks again, i think we're on to something here. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
woodz93
Starting Member
9 Posts |
Posted - 2009-02-08 : 17:34:52
|
| the spid appears in the BlkBy column! as a precaution, other invocations of stored procedures are commented out on the page to isolate this single stored procedure. so i made sure that at that moment in time, only that stored procedure runs. where do we go from here? I don't know what else to do to restructure that query to run more efficiently. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
woodz93
Starting Member
9 Posts |
Posted - 2009-02-09 : 13:07:59
|
Ok, so i ran it, and it returned a 'Language Event' and an Update Query. Quite puzzled about that query - maybe it is on an included file that runs with the ASP page. You're really a big help, tkizer. Are we on to something? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
woodz93
Starting Member
9 Posts |
Posted - 2009-02-09 : 14:31:09
|
| declare @P1 intset @P1=180150019declare @P2 intset @P2=1declare @P3 intset @P3=2declare @P4 intset @P4=1exec sp_cursoropen @P1 output, N'SELECT cust_id from inventory_custodian where id = 108', @P2 output, @P3 output, @P4 outputselect @P1, @P2, @P3, @P4goexec sp_cursorfetch 180150019, 16, 1, 1godeclare @P1 intset @P1=1declare @P2 intset @P2=1exec sp_cursorfetch 180150019, 256, @P1 output, @P2 outputselect @P1, @P2godeclare @P1 intset @P1=180150020declare @P2 intset @P2=8declare @P3 intset @P3=1declare @P4 intset @P4=1exec sp_cursoropen @P1 output, N'SELECT inventory_id FROM users WHERE id = ''194''', @P2 output, @P3 output, @P4 outputselect @P1, @P2, @P3, @P4goexec sp_cursorfetch 180150020, 16, 1, 1godeclare @P1 intset @P1=1declare @P2 intset @P2=1exec sp_cursorfetch 180150020, 256, @P1 output, @P2 outputselect @P1, @P2goUPDATE users SET inventory_id = 3 where id = 194godeclare @P1 intset @P1=180150000declare @P2 intset @P2=8declare @P3 intset @P3=1declare @P4 intset @P4=9exec sp_ddopen @P1 output, N'sp_sproc_columns', @P2 output, @P3 output, @P4 output, N'pdateCustodian', NULL, NULL, NULLselect @P1, @P2, @P3, @P4goexec sp_cursorfetch 180150000, 2, 1, 1goexec sp_cursorfetch 180150000, 2, 1, 1goexec sp_cursorfetch 180150000, 2, 1, 1goexec sp_cursorfetch 180150000, 2, 1, 1goexec sp_cursorfetch 180150000, 2, 1, 1goexec sp_cursorfetch 180150000, 2, 1, 1goexec sp_cursorfetch 180150000, 2, 1, 1goexec sp_cursorfetch 180150000, 2, 1, 1goexec sp_cursorfetch 180150000, 2, 1, 1goexec sp_cursorfetch 180150000, 2, 1, 1goexec sp_cursorclose 180150000goSELECT N'Testing Connection...'goEXECUTE msdb.dbo.sp_sqlagent_get_perf_countersgoSELECT N'Testing Connection...'goEXECUTE msdb.dbo.sp_sqlagent_get_perf_countersgoexec pdateCustodian 'test32', 'test22', 'test', 'test', '111111111', 'test', 'test', 108goexec sp_cursorclose 180150019goexec sp_cursorclose 180150020goSELECT N'Testing Connection...'goEXECUTE msdb.dbo.sp_sqlagent_get_perf_countersgoThe spid in question is 53, and EventType is RPC Event. Hope that helps. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2009-02-09 : 14:57:23
|
| I can't tell from that output what is causing it. I have a feeling it's this part though: "SELECT cust_id from inventory_custodian where id = 108'". My guess is that the application is locking the data on that SELECT query and then the UPDATE gets blocked. You could add lock information to the trace, although that might produce a lot of rows and therefore it would be hard to troubleshoot over the Internet on this. Instead, I'd recommend running sp_lock BlockingSpidGoesHere while the update stored procedure is running. You'll need to first get the spidNo from sp_who2 again as it can change each time you do this. Make sure you are viewing the blocking culprit spid and not the spid for the update. You'd first locate the spid for the update and then look at the BlkBy column.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
woodz93
Starting Member
9 Posts |
Posted - 2009-02-09 : 15:26:49
|
| Ok, so this time i scrutinized EVERY include directive on the web page, and have found that one of the includes basically open a connection, fetches data, and then a separate directive closes the I/O stream at the very end of the page. So, based on what you are saying, the I/O requests are 'hanging' and as a result blocking others from committing? Just to experiment, i retooled the page so that the connection opens/closes after EACH query as opposed to opening upon loading the page and closing when the page has been loaded. Guess what - it worked! There could be performance issues to this though, i'm sure...? Let know what you think. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
woodz93
Starting Member
9 Posts |
Posted - 2009-02-09 : 16:06:45
|
| Ok...sorry to change the subject on you. Agreed, not a good idea.So i run sp_lock(SPID) and i get four columns with information:spid dbid ObjId IndId Type Resource Mode Status 53 8 0 0 DB S GRANT53 8 878626173 0 TAB IX GRANT53 8 878626173 0 PAG 1:372 IU GRANT53 8 878626173 0 RID 1:372:11 U GRANT Thanks again for all your help! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
woodz93
Starting Member
9 Posts |
Posted - 2009-02-09 : 16:30:48
|
| Brilliant job, tkizer! I spent a week being a sleuth and only got halfway here (i think). I'll get to work on the application. You are indeed the SQL goddess! I'll ask away again should i need more insight. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|