?? SQL View on SQL Server Times out but in Access it works, what's up? (1 Viewer)

boblarson

Smeghead
Local time
Yesterday, 23:51
Joined
Jan 12, 2001
Messages
32,059
We have a SQL Server view that is using a PIVOT and when running the view on SQL Server it times out. But if I link to the view in Access, and then run it in Access, it works just fine. Anybody ever see that before?
 

Banana

split with a cherry atop.
Local time
Yesterday, 23:51
Joined
Sep 1, 2005
Messages
6,318
How long does it take for the view to execute?
 

boblarson

Smeghead
Local time
Yesterday, 23:51
Joined
Jan 12, 2001
Messages
32,059
How long does it take for the view to execute?

In SQL Server, we have not gotten it to execute fully. It times out at about 40 seconds.

In Access it takes about 2 seconds to run and return data.

Now that is when pulling all records from the table (85,000+). But if we limit it, to PropertyID, PeriodYear, and PeriodQuarter it is almost instantaneous in Access and just a little longer in SQL Server (again - strange as it is all being done on SQL Server in both instances).
 

Banana

split with a cherry atop.
Local time
Yesterday, 23:51
Joined
Sep 1, 2005
Messages
6,318
Is view being run as a part of procedure? I know I had a case where SQL Server would time out if there was a pending transaction against the table I was trying to work on. For example, this:

Code:
BEGIN TRANSACTION;
TRUNCATE TABLE aTable;
SELECT * FROM aTable;
COMMIT;

would stall out. Do you have logic something like that, perhaps?
 

boblarson

Smeghead
Local time
Yesterday, 23:51
Joined
Jan 12, 2001
Messages
32,059
Nope, just a view.

Code:
SELECT     PropertyFK, PeriodYear, PeriodQuarter, [1] AS [Cash], [2] AS [Accounts Receivable Tenants], [3] AS [Accounts Receivable Other], 
                      [4] AS [Prepaid Expenses], [5] AS [Tenant Security Deposits], [6] AS [Other Current Assets], [7] AS [Replacement Reserves], 
                      [8] AS [Tax and Escrow Insurance], [9] AS [Operating Reserve], [10] AS [Other Reserve], [11] AS [Land], [12] AS [Buildings], 
                      [13] AS [Equipment and Furniture], [14] AS [Accumulated Depreciation], [15] AS [AR Syndication Proceeds], [16] AS [Amortized Expenses], 
                      [17] AS [Other Assets], [18] AS [Accounts Payable], [19] AS [Accrued Expense], [20] AS [Accrued Interest], [21] AS [Accrued Property Tax], 
                      [22] AS [Tenant Security Deposit Liability], [23] AS [Current Notes Payable], [24] AS [Other Current Liabilities], [25] AS [Hard Long Term Debt], 
                      [26] AS [Deferred Soft Debt], [27] AS [Deferred Soft Interest], [28] AS [Debt Added], [29] AS [GP Loans], [30] AS [Development Fee Payable], 
                      [31] AS [Accrued LP Fees Payable], [32] AS [Accrued GP Fees Payable], [33] AS [Other Long Term Liabilities], [34] AS [Limited Partners Capital], 
                      [35] AS [General Partners Capital], [36] AS [Other Capital Account]
FROM         (SELECT     dbo.AccountBalance.PropertyFK, dbo.AccountBalance.PeriodYear, dbo.AccountBalance.PeriodQuarter, dbo.AccountBalance.AccountFK, 
                                              dbo.AccountBalance.Amount
                       FROM          dbo.AccountBalance INNER JOIN
                                              dbo.LUAccount ON dbo.AccountBalance.AccountFK = dbo.LUAccount.AccountID INNER JOIN
                                              dbo.LUAccountCategory ON dbo.LUAccount.AccountCategoryFK = dbo.LUAccountCategory.AccountCategoryID INNER JOIN
                                              dbo.LUAccountType ON dbo.LUAccountCategory.AccountTypeFK = dbo.LUAccountType.AccountTypeID
                       WHERE      (dbo.LUAccountType.StatementTypeFK = 1)) A PIVOT (SUM(Amount) FOR AccountFK IN ([1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], 
                      [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31], [32], [33], [34], [35], [36])) B
 

Banana

split with a cherry atop.
Local time
Yesterday, 23:51
Joined
Sep 1, 2005
Messages
6,318
Next question would be -- what if you remove the PIVOT? Does the timeout goes away?
 

boblarson

Smeghead
Local time
Yesterday, 23:51
Joined
Jan 12, 2001
Messages
32,059
Yep, it sure does. We'd already checked that and we actually had assumed we might have to use a table which was updated every time someone made a change to the data. But the funny thing is, if we use Access (which we are doing anyway, it isn't a problem). It is only a problem if we want to try to test the view on SQL Server.
 

Banana

split with a cherry atop.
Local time
Yesterday, 23:51
Joined
Sep 1, 2005
Messages
6,318
Right.

I guess the next step I'd do is to try and fire up SSMS on a different computer and see what happens there.
 

Banana

split with a cherry atop.
Local time
Yesterday, 23:51
Joined
Sep 1, 2005
Messages
6,318
Well, that's a good ol' noodle scratcher you got there, Bob.

I'm very curious about this. Do you think you can share some bogus data & table structure and other SQL needed to reproduce this? I'd like to try this on my SQL Server and see what I get here. (BTW, are you using SS2005?)
 

boblarson

Smeghead
Local time
Yesterday, 23:51
Joined
Jan 12, 2001
Messages
32,059
Well, that's a good ol' noodle scratcher you got there, Bob.

I'm very curious about this. Do you think you can share some bogus data & table structure and other SQL needed to reproduce this? I'd like to try this on my SQL Server and see what I get here. (BTW, are you using SS2005?)
I am on SS2005. Don't know about the data part. I might be able to come up with some bogus data, but at the moment we're too busy for me to be able to go about it. We can check later. It isn't a show stopper but I am boggled as to why that might be happening. I might post to the mvp newsgroups too, just to see if anyone else has had this type of experience before.
 

Banana

split with a cherry atop.
Local time
Yesterday, 23:51
Joined
Sep 1, 2005
Messages
6,318
If possible, do share the results however you get it- I'm very curious how such thing could possibly happen! It certainly is counterintuitive.
 

LPurvis

AWF VIP
Local time
Today, 07:51
Joined
Jun 16, 2008
Messages
1,269
I think one thing to keep bearing in mind is that SSMS isn't SQL Server.
I've no doubt it's tempting to think of it that way - but it's just another interface tool (writen using .NET tools) to access SQL Server. It wraps functionality provided by the system stored procedures that SQL Server exposes - giving a very integrated feel.

Ultimately the providers it accesses SQL Server with should be better tailored for fast dedicated access (and it's often running on the same machine, removing network considerations).
It's possible that there's a performance bottleneck in its execution in this instance - or a rendering issue.
Access will generally perform a progressive request for the data whereas SSMS waits for full execution to display all the results. This might be making the difference in this case (though a Pivot in general is, by definition, aggregated and so doesn't lend itself so well to progressive execution).

Have you tried executing the request by other means? An asynchronous execution of the view through ADO for example? Or even a .NET client with, in theory, the same tools as SSMS has available ;-).

Cheers.
 

boblarson

Smeghead
Local time
Yesterday, 23:51
Joined
Jan 12, 2001
Messages
32,059
Nope, haven't had the opportunity to try any other methods. We're under a tight deadline so as long as it works in Access or for our VB6 program we are good to go. We'll investigate further when we get to a point where we can. Right now we have to finish this project (including user testing) by Mid February, so any extra time spent on some is not going to help at this point. But I'm sure we will as soon as we can.
 

Users who are viewing this thread

Top Bottom