Showing posts with label time. Show all posts
Showing posts with label time. Show all posts

Friday, March 30, 2012

Problem with SqlCacheDependency

I've set up a SqlCacheDependency in my Asp.Net application, but the dependency invalidates the cache immediately every time the page is hit.

I think the problem may be with my SQL Query, but it seems to me to meet the requirements on the Special Considerations When Using Query Notifications page on MSDN. Could someone take a look at this query and tell me if I've done something wrong? Thank you.

Here's my query:

Code Snippet

USE [chameleon]

GO

SET ANSI_NULLS ON

GO

SET ANSI_PADDING ON

GO

SET ANSI_WARNINGS ON

GO

SET CONCAT_NULL_YIELDS_NULL ON

GO

SET QUOTED_IDENTIFIER ON

GO

SET NUMERIC_ROUNDABORT OFF

GO

SET ARITHABORT ON

GO

ALTER PROCEDURE [dbo].[usp_customers_by_site_id]

@.site_id INT

AS

SELECT

customers.customer_id,

customers.name,

customers.po_prefix,

customers.dt_created,

customers.created_by AS auid,

customers.po_required

FROM dbo.customers

WHERE customers.site_id = @.site_id

AND customers.is_active = 1

and here's the code in my Asp.Net site where I try to use the SqlCacheDependency:

Code Snippet

public List<Customer> GetCustomersBySite(int siteID)

{

List<Customer> customers = new List<Customer>();

if (HttpRuntime.Cache["CustomersBySite" + siteID] != null){

customers = (List<Customer>)HttpRuntime.Cache["CustomersBySite" + siteID];

}

else

{

using (SqlCommand command = new SqlCommand("usp_customers_by_site_id", Connection)){

command.CommandType = CommandType.StoredProcedure;

command.Parameters.Add("@.site_id", SqlDbType.Int).Value = GetDBValue(siteID, false);

SqlCacheDependency dependency = new SqlCacheDependency(command);

try{

Connection.Open();

SqlDataReader reader;

reader = command.ExecuteReader(CommandBehavior.SingleResult);

while (reader.Read()){

customers.Add(PopulateCustomer(reader));

}

HttpRuntime.Cache.Insert("CustomersBySite" + siteID, customers, dependency, DateTime.Now.AddMinutes(Configuration.CacheDuration), System.Web.Caching.Cache.NoSlidingExpiration);

}

finally{

Connection.Close();

}

}

}

return customers;

}

My apologies. I posted this in the wrong forum.

-Brad

Monday, March 26, 2012

Problem with SQL Query Analyzer

Hi,
I have the following problem: if I call a stored procedure from a program (via COM+/OLE DB) I measure the response time and I get something around 400 ms (including reading the data from the result set, a couple of MoveNext operations).
Now if I call the very same stored procedure within the SQL Query Analyzer, it takes almost 8 seconds until I can see the results! Does anybody know why?
Is the Query Analyzer so badly implemented when it reads the results and displays them?
Even if I eliminate the results (by adding select top 0 in my final query in the stored procedure) it still takes about 7 seconds within the Query Analyzer.
My bigger problem is that I use the query analyzer to fine-tune my application and it seems I can't rely on the results, because the same queries run differently once they are called from the application.
It's weird because I also get these confusing response times displayed in the Profiler! At the beginning I thought that the Query Analyzer adds some overhead, but why do I get different times in the Profiler?
Any hints/tips? Did anyone experience that before?
Thanks in advance,
Florin Micle
Execution plans can differ for several reasons. Different SET option is one potential reason. The first thing
to do is to compare the execution plans and see if they are the same or not.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"fmicle" <fmicle@.hotmail.com> wrote in message news:824E53F3-AC7C-4C1C-AFD5-06D4609F8714@.microsoft.com...
> Hi,
> I have the following problem: if I call a stored procedure from a program (via COM+/OLE DB) I measure the
response time and I get something around 400 ms (including reading the data from the result set, a couple of
MoveNext operations).
> Now if I call the very same stored procedure within the SQL Query Analyzer, it takes almost 8 seconds until
I can see the results! Does anybody know why?
> Is the Query Analyzer so badly implemented when it reads the results and displays them?
> Even if I eliminate the results (by adding select top 0 in my final query in the stored procedure) it still
takes about 7 seconds within the Query Analyzer.
> My bigger problem is that I use the query analyzer to fine-tune my application and it seems I can't rely on
the results, because the same queries run differently once they are called from the application.
> It's weird because I also get these confusing response times displayed in the Profiler! At the beginning I
thought that the Query Analyzer adds some overhead, but why do I get different times in the Profiler?
> Any hints/tips? Did anyone experience that before?
> Thanks in advance,
> Florin Micle
|||Perhaps your data happened to be cached in some instances. Try clearing the
cache using DBCC DROPCLEANBUFFERS before testing the queries using.
As Tibor mentioned, different execution plans may be another cause, which
you can also capture using Profiler.
Regards
Ray Mond
"fmicle" <fmicle@.hotmail.com> wrote in message
news:824E53F3-AC7C-4C1C-AFD5-06D4609F8714@.microsoft.com...
> Hi,
> I have the following problem: if I call a stored procedure from a program
(via COM+/OLE DB) I measure the response time and I get something around 400
ms (including reading the data from the result set, a couple of MoveNext
operations).
> Now if I call the very same stored procedure within the SQL Query
Analyzer, it takes almost 8 seconds until I can see the results! Does
anybody know why?
> Is the Query Analyzer so badly implemented when it reads the results and
displays them?
> Even if I eliminate the results (by adding select top 0 in my final query
in the stored procedure) it still takes about 7 seconds within the Query
Analyzer.
> My bigger problem is that I use the query analyzer to fine-tune my
application and it seems I can't rely on the results, because the same
queries run differently once they are called from the application.
> It's weird because I also get these confusing response times displayed in
the Profiler! At the beginning I thought that the Query Analyzer adds some
overhead, but why do I get different times in the Profiler?
> Any hints/tips? Did anyone experience that before?
> Thanks in advance,
> Florin Micle
|||Hi, when you look at profiler do you to capture exactly what it being run when the program calls the sp? I ask because unless the inputs are exactly the same you could get differing results. I've seen this with datetime inputs where query plans have been
different depending on the format of the date input. As Tibor says, did the query plan show anything different? I assume they must have done? You've tried the TOP 0 which should eliminate the displaying of the results and as Ray says you can drop the data
from cache (and run CHECKPOINT) to give the two approaches a level playing field. I feel the answer will be in your execution plan and I'd expect either as Tibor says, your SET options will be the root, or that it's perhaps something to do with one or mo
re of your sp inputs.
Alicia
Http://www.sqlporn.co.uk
|||Well, how am I suppose to know how exactly the query is executed and which query plan is taken?
I can see in the Profiler, that the exact same query is launched when I call it from my application and when I call it from the Query Analyzer. The query plan I can only see in the Query Analyzer, if I run my query in it, so I'll never know what plan is a
ctually taken when my query runs from the application.
That's exactly my problem, I can't tune my application properly, since the queries work differently in the Query Analyzer and from my app.
By the way, to answer your questions, the plan is always the same for my query.
I also think there are some bugs in the Profiler.
My stored procedure, let's name it SP1 calls 2 other SP's, which are very fast, let's call them SP2 and SP3.
So SP1 looks something like:
...
EXEC SP2
EXEC SP3
Do some complex queries
...
In the profiler, every time I call SP1, I get 3 SP Completed events, like this (two consecutive calls, you can see the effects of the cache, which is ok):
EventClass TextData Duration
SP:Completedexec SP1 0
SP:Completedexec SP1 0
SP:Completedexec SP1 453
SP:Completedexec SP1 0
SP:Completedexec SP1 0
SP:Completedexec SP1 313
Now, I call the same SP two times from the Query Analyzer, this is what I get in the profiler:
EventClass TextData Duration
SP:Completedexec SP2 0
SP:Completedexec SP3 0
SP:Completedexec SP1 1926
SP:Completedexec SP2 0
SP:Completedexec SP3 0
SP:Completedexec SP1 2005
The profiling mechanisms seem to be different, if the SP1 is called from the Query Analyzer it looks OK, but from my app, there seems to be a bug somwhere in the event handling in the Profiler.
Any ideas?
|||I can't believe this, if I delete the proccache (dbcc freeproccache) I get almost the same response times within QA like from my application!
About 600 ms, which is much better than 2 seconds!
What can make QA generate such a bad query plan?
Another thing: my application (C++) runs as a COM object in COM+. I wrote a small C++ program which does the exact same thing (calls the same stored procedure) and this is slower than when it runs in COM+. I use ATL OLE DB to connect to the DB in both cas
es.
I can only imagine, that there must be some magic in COM+, which sets some parameters differently, thus making the SQL Server run faster/better when called from COM+.
Confusing...
|||> What can make QA generate such a bad query plan?
The cached plan may have been generated for a query that uses parameter
values that do not fall into the same distribution pattern that the later
query has. However, this is unlikely in your case since you mentioned that
they are both using the same query.
I suggest checking the execution plan from both sides. Use Profiler to
capture the execution plan, using the Show Plan Statistics event under the
Performance heading.
Regards
Ray Mond
"fmicle" <fmicle@.hotmail.com> wrote in message
news:D42860F2-6C23-48C0-AA90-9301F2697191@.microsoft.com...
> I can't believe this, if I delete the proccache (dbcc freeproccache) I get
almost the same response times within QA like from my application!
> About 600 ms, which is much better than 2 seconds!
> What can make QA generate such a bad query plan?
> Another thing: my application (C++) runs as a COM object in COM+. I wrote
a small C++ program which does the exact same thing (calls the same stored
procedure) and this is slower than when it runs in COM+. I use ATL OLE DB to
connect to the DB in both cases.
> I can only imagine, that there must be some magic in COM+, which sets some
parameters differently, thus making the SQL Server run faster/better when
called from COM+.
> Confusing...
|||No, you're right, it makes sense. When I call the SP from COM+, I use placeholders and Accessors to bind my parameters.
But I get the exact same query text in the profiler.
On the other hand, if I do the same thing outside COM+, even using the parameters, I still get the bad plan (WITH PREFETCH).
I can only reach almost the same speed outside COM+ if I delete the PROCCACHE.

Wednesday, March 21, 2012

Problem with simplified chinese

I have a 3 layer system, SQL Server 2000 database, COM+ dll's (VC++ 6) and
ASP frontend, this system has been in production for quite some time using
english, spanish and portuguese versions. Now I've been asked to test the
system to function with Simplified chinese. The development of the system
was outsourced and we don't have communication with the company (some sort
of legal problems i think).
Now, I've been reviewing the code and recompiled one of the core DLL's for
unicode support with no problems, I've tested the database (SQL Server 2000)
inserting Simplified Chinese characters and the DB supports it fine (the DB
fields are NVARCHAR), in the ASP frontend, the retrievel process (calling
the COM+ DLL functions) works fine displaying this data I inserted directly
in the DB.
However, when I try inserting this data through the ASP frontend I'm getting
errors regarding the length of the strings, I'm testing the data insertion
in a field limited to 100 characters, the data I'm testing are 23 Simplified
Chinese symbols or characters and when I insert them directly in the DB
there is no problem, the DB correctly interprets the string as 23 characters
long, but when I test the length of the same string on the ASP page it says
its 183 characters long, so I'm guessing the ASP code is doing some kind of
implicit conversion, I already tried setting the asp session codepage to
65001 for unicode support with the same outcome. Any ideas or tips?
Sorry for the long post, I would reaaly appreciate any kind of help.
David
David A. Caballero J. wrote:

> Sorry for the long post, I would reaaly appreciate any kind of help.
> David
I have a PDF we devised for clients who want to run our ASP package in
Chinese (unicode) - I think it deals with some of the issues you've come
across. Let me know if I can send it to your hotmail address (I'm
assuming it's genuine) and I'll send it over.
The reason you are seeing more characters is because the chars are
displayed in web page HTML source as numerical codes made up of ASCII chars.

captain_flackTONYBLAIRFROMOFFICE@.hotmail.com
(remove Tony Blair from office to contact me)

Tuesday, March 20, 2012

Problem with sending email

This is the first time I am setting up an operator so that I can get job
notifications to my email. When I create an operator any type in my address
and click test. It gives me the following error:
Problem occoured while attempting to resolve the address 'my email address'.
Mapi error code number -2147221233
Thanks
The first thing would be to check to ensure that SQL Mail has been setup
correctly as typically the MAPI errors occur as a result of an incorrect
configuration. The KB Article
http://support.microsoft.com/default...b;en-us;263556 describes how
to Configure SQL Mail and the KB article
http://support.microsoft.com/kb/315886/EN-US/ details Common SQL Mail
Problems.
- Peter Ward
WARDY IT Solutions
"Amit" wrote:

> This is the first time I am setting up an operator so that I can get job
> notifications to my email. When I create an operator any type in my address
> and click test. It gives me the following error:
> Problem occoured while attempting to resolve the address 'my email address'.
> Mapi error code number -2147221233
> Thanks

Problem with sending email

This is the first time I am setting up an operator so that I can get job
notifications to my email. When I create an operator any type in my address
and click test. It gives me the following error:
Problem occoured while attempting to resolve the address 'my email address'.
Mapi error code number -2147221233
ThanksThe first thing would be to check to ensure that SQL Mail has been setup
correctly as typically the MAPI errors occur as a result of an incorrect
configuration. The KB Article
http://support.microsoft.com/defaul...kb;en-us;263556 describes how
to Configure SQL Mail and the KB article
http://support.microsoft.com/kb/315886/EN-US/ details Common SQL Mail
Problems.
- Peter Ward
WARDY IT Solutions
"Amit" wrote:

> This is the first time I am setting up an operator so that I can get job
> notifications to my email. When I create an operator any type in my addres
s
> and click test. It gives me the following error:
> Problem occoured while attempting to resolve the address 'my email address
'.
> Mapi error code number -2147221233
> Thanks

Problem with sending email

This is the first time I am setting up an operator so that I can get job
notifications to my email. When I create an operator any type in my address
and click test. It gives me the following error:
Problem occoured while attempting to resolve the address 'my email address'.
Mapi error code number -2147221233
ThanksThe first thing would be to check to ensure that SQL Mail has been setup
correctly as typically the MAPI errors occur as a result of an incorrect
configuration. The KB Article
http://support.microsoft.com/default.aspx?scid=kb;en-us;263556 describes how
to Configure SQL Mail and the KB article
http://support.microsoft.com/kb/315886/EN-US/ details Common SQL Mail
Problems.
- Peter Ward
WARDY IT Solutions
"Amit" wrote:
> This is the first time I am setting up an operator so that I can get job
> notifications to my email. When I create an operator any type in my address
> and click test. It gives me the following error:
> Problem occoured while attempting to resolve the address 'my email address'.
> Mapi error code number -2147221233
> Thanks

Problem with select to another server.

Hello All!

This is the first time I'm working between two SQL servers. Here is a simple SELECT statement.

DECLARE @.Acct nvarchar(50)

SELECT First_Name, Last_Name, Age, DOB, Account_Number

FROM [MKE01-Demo-XX].SAHPharm.dbo.Active_Orders

WHERE [MKE01-2NX2461].[Pharm Test Local].dbo.Active_Orders = @.Acct

Here is the error

Msg 4104, Level 16, State 1, Line 4

The multi-part identifier "MKE01-2NX2461.Pharm Test Local.dbo.Active_Orders" could not be bound.

What am I doing wrong?

Thanks!

Rudy

MKE01-2NX2461 is set up as a Linked Server in MKE01-Demo-XX?

|||

You are attempting to compare a table to a variable.

WHERE [MKE01-2NX2461].[Pharm Test Local].dbo.Active_Orders = @.Acct

It would be nice, but it isn't going to happen...

But more critically, I don't see any relationship between the two tables from the two databases. How would a row from [MKE01-2NX2461].[Pharm Test Local].dbo.Active_Orders be connected to the table [MKE01-Demo-XX].SAHPharm.dbo.Active_Orders in such a way that using the variable value against one table 'should' return a row from the other table.

I think that something isn't quite right here... (Perhaps a JOIN is missing.)

|||

Hi guys!

Ah yes. A JOIN would make sense. Mke Demo is the linked serve on MKe 29nx... So let me give that a shot. I'm sure I'll be back here with a question or two.

Thanks!

Rudy

|||

Perhaps something more like this?

Code Snippet


DECLARE @.Acct nvarchar(50)


SET @.Acct = {someValue}


SELECT
x.First_Name,
x.Last_Name,
x.Age,
x.DOB,
x.Account_Number
FROM [MKE01-Demo-XX].SAHPharm.dbo.Active_Orders x
JOIN [MKE01-2NX2461].[Pharm Test Local].dbo.Active_Orders t
ON x.Account_Number = t.Account_Number
WHERE x.Account_Number = @.Acct

This assumes that the values you wish to return are located in the [MKE01-Demo-XX].SAHPharm.dbo.Active_Orders table, and that both tables have the Account_Number column to link the data.

Friday, March 9, 2012

problem with report parameters in nested IIf

I have the following to diplay the frequecny a report is run for -
based on parameters selected at run time...
=3D"Report Period " & IIf(Parameters!StartDate.Value > "01/01/1900",
Parameters!StartDate.Value & " to " & IIf(Parameters!EndDate.Value >
"01/01/1900", Parameters!EndDate.Value,
Parameters!StartDate.Value.AddHours(1)), Parameters!Frequency.Label)
but if I leave the start and end date null I get an error #Error and
the following...
The value expression for the textbox 'textbox1' contains an error:
Object variable or With block variable not set.
However, if I replace the above with the following (instead of printing
out the date parameter value in the inner iif, print out a string
instead)....
=3D"Report Period " & IIf(Parameters!StartDate.Value > "01/01/1900",
Parameters!StartDate.Value & " to " & IIf(Parameters!EndDate.Value >
"01/01/1900", "Parameters!EndDate.Value",
"Parameters!StartDate.Value.AddHours(1)"), Parameters!Frequency.Label)
it works fine and will display the frequency if both dates are null.
Any idea why this is?
Also as an aside - is there a better way to check is a date field is
null instead of > "01/01/1900"'
Thanks in advance,
Gear=F3idThis occurs for 2 reasons:
1. an Iif statement always evaluates all parts of an equation.
Therefore, if 1/2 of the statement is invalid, the whole thing throws an
error.
2. You're trying to AddHours(1) to a null value, which throws an error.
I don't know why putting it in "" causes it to work, though.
As for a better option than > "01/01/1900", I recommend >
DateTime.MinValue, as that is the default value for an unassigned DateTime.
Ciao,
Noah
Gearoid wrote:
> I have the following to diplay the frequecny a report is run for -
> based on parameters selected at run time...
> ="Report Period " & IIf(Parameters!StartDate.Value > "01/01/1900",
> Parameters!StartDate.Value & " to " & IIf(Parameters!EndDate.Value >
> "01/01/1900", Parameters!EndDate.Value,
> Parameters!StartDate.Value.AddHours(1)), Parameters!Frequency.Label)
> but if I leave the start and end date null I get an error #Error and
> the following...
> The value expression for the textbox 'textbox1' contains an error:
> Object variable or With block variable not set.
> However, if I replace the above with the following (instead of printing
> out the date parameter value in the inner iif, print out a string
> instead)....
> ="Report Period " & IIf(Parameters!StartDate.Value > "01/01/1900",
> Parameters!StartDate.Value & " to " & IIf(Parameters!EndDate.Value >
> "01/01/1900", "Parameters!EndDate.Value",
> "Parameters!StartDate.Value.AddHours(1)"), Parameters!Frequency.Label)
> it works fine and will display the frequency if both dates are null.
> Any idea why this is?
> Also as an aside - is there a better way to check is a date field is
> null instead of > "01/01/1900"'
> Thanks in advance,
> Gearóid
>|||Hey Noah,
Thanks for getting back to me on this. I put it aside for a while but
have to get it sorted now.
I reckon you're right about it trying to add 1 hour to a null value and
bombing out. But it seems kinda crazy that it would try to evaluate
all parts of an IIf statement. How would I conditionally add an hour
to a datetime value so if it's not null? I thought that's what an if
statements for?!...

Wednesday, March 7, 2012

Problem with query taking a long time.

I have a large SQL table, called Event, that has 4.6 million records in it.
My problem is that one particular query on the table is taking over 30
seconds to run. All the other queries that I have take under 1 second to
run. I have tried numerous index changes, but it seems that nothing helps.
I have even removed all the indexes (excluding the primary key and clustered
index), and had the Index Tuning Wizard generate new indexes, but with no
luck. Below I have listed the SQL Queries that I am running, and the SQL
statements for creating all of the related tables and views. You will notic
e
that I am calling a view to retrieve the records. Any suggestions would be
greatly appreciated.
Good Query 1 (< 1 sec to run on 4.6 million records)
SELECT top 15 * FROM vw_HistEventDisplayGrid
WHERE SeqNo NOT IN (SELECT TOP 0 SeqNo FROM vw_HistEventDisplayGrid
WHERE (NAME like 'a%') AND (Sphere = 0 OR Sphere IN (SELECT Partition FROM
Sphere WHERE OperPrivId = 33))
ORDER BY NAME ASC, EDATE DESC)
AND (NAME like 'a%') AND (Sphere = 0 OR Sphere IN (SELECT Partition FROM
Sphere WHERE OperPrivId = 33))
ORDER BY NAME ASC, EDATE DESC
Good Query 2 (< 1 sec to run on 4.6 million records)
SELECT top 15 * FROM vw_HistEventDisplayGrid
WHERE SeqNo NOT IN (SELECT TOP 0 SeqNo FROM vw_HistEventDisplayGrid
WHERE (Sphere = 0 OR Sphere IN (SELECT Partition FROM Sphere WHERE
OperPrivId = 33))
ORDER BY NAME DESC, EDATE DESC)
AND (Sphere = 0 OR Sphere IN (SELECT Partition FROM Sphere WHERE OperPrivId
= 33))
ORDER BY NAME DESC, EDATE DESC
Bad Query (> 30 seconds on 4.6 million records)
SELECT top 15 * FROM vw_HistEventDisplayGrid
WHERE SeqNo NOT IN (SELECT TOP 0 SeqNo FROM vw_HistEventDisplayGrid
WHERE (Sphere = 0 OR Sphere IN (SELECT Partition FROM Sphere WHERE
OperPrivId = 33))
ORDER BY NAME ASC, EDATE DESC)
AND (Sphere = 0 OR Sphere IN (SELECT Partition FROM Sphere WHERE OperPrivId
= 33))
ORDER BY NAME ASC, EDATE DESC
SQL for creating tables and views:
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[vw_HistEventDisplayGrid]') and OBJECTPROPERTY(id,
N'IsView') = 1)
drop view [dbo].[vw_HistEventDisplayGrid]
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[Event]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Event]
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[Oper]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Oper]
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[Sphere]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Sphere]
GO
CREATE TABLE [dbo].[Event] (
[Seqno] uniqueidentifier ROWGUIDCOL NOT NULL ,
[Priority] [smallint] NULL ,
[Cat] [smallint] NULL ,
[PnlNo] [smallint] NULL ,
[EDate] [datetime] NULL ,
[Number] [smallint] NULL ,
[Status] [smallint] NULL ,
[Facno] [smallint] NULL ,
[Badge] [bigint] NULL ,
[Class] [varchar] (48) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Description] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Name] [varchar] (48) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Arch] [smallint] NULL ,
[AckOpr] [smallint] NULL ,
[AckTStamp] [datetime] NULL ,
[Actions] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RespReq] [bit] NULL ,
[Sphere] [int] NULL ,
[Tag] [int] NULL ,
[Pending] [bit] NULL ,
[HasPhoto] [bit] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[Oper] (
[OpNo] [smallint] NOT NULL ,
[ScrName] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Name] [varchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Passwrd] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Priv] [int] NULL ,
[Changed] [datetime] NULL ,
[GroupNo] [smallint] NULL ,
[AckTO] [smallint] NULL ,
[Opt] [smallint] NULL ,
[Flag] [bit] NULL ,
[AutoAck] [smallint] NULL ,
[ShowPrior] [smallint] NULL ,
[UP_CBCaptions] [bit] NULL ,
[UP_CBIcons] [bit] NULL ,
[UP_UseBg] [bit] NULL ,
[UP_BgIndex] [smallint] NULL ,
[UP_X] [smallint] NULL ,
[UP_Y] [smallint] NULL ,
[UP_Width] [smallint] NULL ,
[UP_Height] [smallint] NULL ,
[UP_Monitor] [bit] NULL ,
[UP_Control] [bit] NULL ,
[UP_ShowPhoto] [bit] NULL ,
[LogOffTime] [int] NULL ,
[EventViewCount] [int] NULL ,
[EventViewDay] [bit] NULL ,
[EventViewSpan] [int] NULL ,
[WebRights] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[OperFontName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[OperFontSize] [int] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Sphere] (
[OperPrivId] [smallint] NOT NULL ,
[GroupId] [smallint] NOT NULL ,
[GroupNo] [smallint] NOT NULL ,
[Changed] [datetime] NULL ,
[Partition] [int] NOT NULL ,
[Restriction] [smallint] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Oper] WITH NOCHECK ADD
CONSTRAINT [PK_Oper] PRIMARY KEY CLUSTERED
(
[OpNo]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Sphere] WITH NOCHECK ADD
CONSTRAINT [PK_Sphere] PRIMARY KEY CLUSTERED
(
[OperPrivId],
[GroupId],
[GroupNo]
) ON [PRIMARY]
GO
CREATE CLUSTERED INDEX [EdateX_Event] ON [dbo].[Event]([EDate]) ON
[PRIMARY]
GO
ALTER TABLE [dbo].[Event] ADD
CONSTRAINT [DF_Event_Seqno] DEFAULT (newid()) FOR [Seqno],
CONSTRAINT [DF__Event__HasPhoto__3DE82FB7] DEFAULT (0) FOR [HasPhoto],
CONSTRAINT [PK_Event] PRIMARY KEY NONCLUSTERED
(
[Seqno]
) ON [PRIMARY]
GO
CREATE INDEX [Event50] ON [dbo].[Event]([AckOpr], [EDate] DESC , [Seqno],
[Class], [Description]) ON [PRIMARY]
GO
CREATE INDEX [Event51] ON [dbo].[Event]([Description], [EDate] DESC ,
[Seqno], [Class]) ON [PRIMARY]
GO
CREATE INDEX [Event52] ON [dbo].[Event]([Class], [EDate] DESC , [Seqno],
[Description]) ON [PRIMARY]
GO
CREATE INDEX [Event53] ON [dbo].[Event]([Class] DESC , [EDate] DESC ,
[Seqno], [Description]) ON [PRIMARY]
GO
CREATE INDEX [Event54] ON [dbo].[Event]([Description]) ON [PRIMARY]
GO
CREATE INDEX [Event55] ON [dbo].[Event]([AckOpr]) ON [PRIMARY]
GO
CREATE INDEX [Event56] ON [dbo].[Event]([Sphere]) ON [PRIMARY]
GO
CREATE INDEX [Event59] ON [dbo].[Event]([Sphere], [Name]) ON [PRIMARY]
GO
CREATE INDEX [Event57] ON [dbo].[Event]([Name], [EDate] DESC ) ON [PRIMARY]
GO
CREATE INDEX [Event58] ON [dbo].[Event]([Name] DESC , [EDate] DESC ) ON
[PRIMARY]
GO
ALTER TABLE [dbo].[Oper] ADD
CONSTRAINT [DF_Oper_OpNo] DEFAULT (1) FOR [OpNo],
CONSTRAINT [DF_Oper_Priv] DEFAULT (0) FOR [Priv],
CONSTRAINT [DF_Oper_GroupNo] DEFAULT (0) FOR [GroupNo],
CONSTRAINT [DF_Oper_AckTO] DEFAULT (60) FOR [AckTO],
CONSTRAINT [DF_Oper_AutoAck] DEFAULT (0) FOR [AutoAck],
CONSTRAINT [DF_Oper_UP_ShowPhoto] DEFAULT (0) FOR [UP_ShowPhoto],
CONSTRAINT [DF_Oper_LogOffTime] DEFAULT (5) FOR [LogOffTime],
CONSTRAINT [DF_Oper_EventViewCount] DEFAULT (50) FOR [EventViewCount]
GO
CREATE INDEX [PKO_Group] ON [dbo].[Oper]([GroupNo]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Sphere] ADD
CONSTRAINT [DF_Sphere_OperPrivId] DEFAULT (1) FOR [OperPrivId],
CONSTRAINT [DF_Sphere_GroupId] DEFAULT (0) FOR [GroupId],
CONSTRAINT [DF_Sphere_GroupNo] DEFAULT (1) FOR [GroupNo],
CONSTRAINT [DF_Sphere_Partition] DEFAULT (0) FOR [Partition]
GO
CREATE INDEX [PKS_GroupID] ON [dbo].[Sphere]([GroupId]) ON [PRIMARY]
GO
CREATE INDEX [PKS_Group] ON [dbo].[Sphere]([GroupNo]) ON [PRIMARY]
GO
CREATE INDEX [PKS_OperPrivID] ON [dbo].[Sphere]([OperPrivId]) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW dbo.vw_HistEventDisplayGrid
AS
SELECT dbo.Event.Seqno, dbo.Event.Priority, dbo.Event.Cat,
dbo.Event.PnlNo, dbo.Event.EDate, dbo.Event.Number, dbo.Event.Status,
dbo.Event.Facno,
dbo.Event.Badge, dbo.Event.Class,
dbo.Event.Description, dbo.Event.Name, dbo.Event.Arch, dbo.Event.AckOpr,
dbo.Event.AckTStamp,
dbo.Event.Actions, dbo.Event.RespReq,
dbo.Event.Sphere, dbo.Event.Tag, dbo.Event.Pending, dbo.Event.HasPhoto,
dbo.Oper.ScrName
FROM dbo.Event LEFT OUTER JOIN
dbo.Oper ON dbo.Event.AckOpr = dbo.Oper.OpNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO"Reza Raquib" <RezaRaquib@.discussions.microsoft.com> wrote in message
news:3B46DDF5-8361-4C96-9925-70ACB477B03F@.microsoft.com...
> Good Query 2 (< 1 sec to run on 4.6 million records)
> SELECT top 15 * FROM vw_HistEventDisplayGrid
> WHERE SeqNo NOT IN (SELECT TOP 0 SeqNo FROM vw_HistEventDisplayGrid
> WHERE (Sphere = 0 OR Sphere IN (SELECT Partition FROM Sphere WHERE
> OperPrivId = 33))
> ORDER BY NAME DESC, EDATE DESC)
> AND (Sphere = 0 OR Sphere IN (SELECT Partition FROM Sphere WHERE
OperPrivId
> = 33))
> ORDER BY NAME DESC, EDATE DESC
> Bad Query (> 30 seconds on 4.6 million records)
> SELECT top 15 * FROM vw_HistEventDisplayGrid
> WHERE SeqNo NOT IN (SELECT TOP 0 SeqNo FROM vw_HistEventDisplayGrid
> WHERE (Sphere = 0 OR Sphere IN (SELECT Partition FROM Sphere WHERE
> OperPrivId = 33))
> ORDER BY NAME ASC, EDATE DESC)
> AND (Sphere = 0 OR Sphere IN (SELECT Partition FROM Sphere WHERE
OperPrivId
> = 33))
> ORDER BY NAME ASC, EDATE DESC
>
I'm not sure if I'm missing something, but I see no differences between
these two queries -- did you paste the wrong one?
Also, did you really mean SELECT TOP 0 ?
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--|||The top 0 is dynamic, as a form of paging. Replace the top 0 with a top 90,
that would be more representative. The only difference between these 2
queries are the ordering of the NAME column. The good query has the NAME
ordered descending. The bad query has the NAME ascending.
Thanks.
"Adam Machanic" wrote:

> "Reza Raquib" <RezaRaquib@.discussions.microsoft.com> wrote in message
> news:3B46DDF5-8361-4C96-9925-70ACB477B03F@.microsoft.com...
> OperPrivId
> OperPrivId
>
> I'm not sure if I'm missing something, but I see no differences between
> these two queries -- did you paste the wrong one?
> Also, did you really mean SELECT TOP 0 ?
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
>|||"Reza Raquib" <RezaRaquib@.discussions.microsoft.com> wrote in message
news:4E9E19FD-624F-4D2F-AE2B-171783E7266D@.microsoft.com...
> The top 0 is dynamic, as a form of paging. Replace the top 0 with a top
90,
> that would be more representative. The only difference between these 2
> queries are the ordering of the NAME column. The good query has the NAME
> ordered descending. The bad query has the NAME ascending.
I think you'll find that re-doing the paging a bit differently is going to
be the best solution -- however, paging is never an easy problem in SQL
Server...
Give this a try and tell me if it helps at all -- or if it compeltely bombs
:) -- (replace both <N>s with the last row number you want, and <M> with the
first row number you want):
SELECT *
FROM (
SELECT TOP <n>
E1.Seqno,
E1.Priority,
E1.Cat,
E1.PnlNo,
E1.EDate,
E1.Number,
E1.Status,
E1.Facno,
E1.Badge,
E1.Class,
E1.Description,
E1.Name,
E1.Arch,
E1.AckOpr,
E1.AckTStamp,
E1.Actions,
E1.RespReq,
E1.Sphere,
E1.Tag,
E1.Pending,
E1.HasPhoto,
E1.ScrName,
COUNT(*) AS Rank
FROM vw_HistEventDisplayGrid E1
JOIN vw_HistEventDisplayGrid E2 ON E2.Name <= E1.Name
AND (E2.Name < E1.Name OR (E2.EDate > E1.EDate))
WHERE EXISTS
(SELECT 1
WHERE E1.Sphere = 0
UNION ALL
SELECT 1
FROM Sphere
WHERE OperPrivId = 33
AND Sphere.Partition = E1.Sphere)
AND EXISTS
(SELECT 1
WHERE E2.Sphere = 0
UNION ALL
SELECT 1
FROM Sphere
WHERE OperPrivId = 33
AND Sphere.Partition = E2.Sphere)
GROUP BY
E1.Seqno,
E1.Priority,
E1.Cat,
E1.PnlNo,
E1.EDate,
E1.Number,
E1.Status,
E1.Facno,
E1.Badge,
E1.Class,
E1.Description,
E1.Name,
E1.Arch,
E1.AckOpr,
E1.AckTStamp,
E1.Actions,
E1.RespReq,
E1.Sphere,
E1.Tag,
E1.Pending,
E1.HasPhoto,
E1.ScrName
ORDER BY E1.NAME ASC, E1.EDATE DESC) y
WHERE Y.theCount BETWEEN <m> AND <n>
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--

Monday, February 20, 2012

Problem with performance after leaving SQL Server Express idle for some time

Hi, everyone!

I have this strange problem... After every time my application leaves sql-server idle (doesn't send anything, doesn't retrieve anything) next command to sql-server processes really long.

I've also noticed this bug/feature/misconfiguration even if I open a DB in Management Studio...

Please, could someone tell me, is there any timer that "puts a DB to sleep" if no one is using it for some time? Can I change the way server behaves in this situation?

I saw this problem once long ago when we had to shovel coal into our PC's to make them run.

In our case, the database server was on a dedicated PC. Someone had installed a graphics-intensive screen-saver. Evertime the screen-saver kicked in performance dropped.

Another possibility: Opening a DB connection takes a long time. You may be timing out and getting kicked out of the server.

|||

Thanks for the reply.

Well, that's not screen saver, definitely. I had this problem both on local machine (obviously when screen saver is not running :) ) and on a remote server, but I know for sure what is going on there too.

And as I understood the second possible reason you're saying server kicks me out, but I've set the timeout to pretty big number (before I did that, I actually was kicked out all the time), but now I don't get connection-not-opened exception or anything else like that.

Everything works pretty smooth all the time (like ASP.NET page loads fast, fast postbacks, management studio works fine) until I leave server alone for some time. After that this damn lag happens (for one time, like it's reconnecting to DB or smth like that) and everything works fine again.

|||

Maybe it's not the database but asp.net.

When all sessions end or time out, your application is shut down. See if the Application_End event is raised.

|||No, i don't think so... First of all, I used the same app with MSDE 2000 and didn't have this issue. Second, I see this issue not only when using my asp.net app, but also WinForms app, and even Management Studio (as I think I mentioned in the first post).

Problem with PAGE HEADER

Dear All

I am Sundaraguru from India.

I have problem with Reporting services header showing time..

I designed the one report. That report Size is 8inch x 41 inches..

What are problems i having in this reports:

1. Report header is not coming in second pages. ( For report header i am not using the report header area, Because the header informations will varying based on the data's. That's Why I placed in the detail sections)

2. While Seeing the preview time it is showing only 11 page ( for 2 record) after exporting to PDF format it showing 32 pages.

How i can solve the above problem.. I have to get is all the page's i have to show report header in all the pages.

I am using SQL Server 2005 , & VS.Net 2005 With November 2006 CTP

And Send your valuable suggestions to following mail id's sundaraguru_s@.apollohealthstreet.com and sundharmail@.yahoo.co.in.

Advance Thanks

Kind Regards
Sundaraguru S

Dear All,

I got the Solution

I place the Repeatable information to the one separate rectangle.. Right the Rectangle -> General -> Data Region (Combo) Select the dataset. (If the Selected dataset is contains then detailed information). And set the hidden property for the rectangle

Add the header and footer information and refer the hidden rectangle contained control informations(Using ReportItems("").Value ).

Kind Regards

Sundaraguru S

Problem with PAGE HEADER

Dear All

I am Sundaraguru from India.

I have problem with Reporting services header showing time..

I designed the one report. That report Size is 8inch x 41 inches..

What are problems i having in this reports:

1. Report header is not coming in second pages. ( For report header i am not using the report header area, Because the header informations will varying based on the data's. That's Why I placed in the detail sections)

2. While Seeing the preview time it is showing only 11 page ( for 2 record) after exporting to PDF format it showing 32 pages.

How i can solve the above problem.. I have to get is all the page's i have to show report header in all the pages.

I am using SQL Server 2005 , & VS.Net 2005 With November 2006 CTP

And Send your valuable suggestions to following mail id's sundaraguru_s@.apollohealthstreet.com and sundharmail@.yahoo.co.in.

Advance Thanks

Kind Regards
Sundaraguru S

Dear All,

I got the Solution

I place the Repeatable information to the one separate rectangle.. Right the Rectangle -> General -> Data Region (Combo) Select the dataset. (If the Selected dataset is contains then detailed information). And set the hidden property for the rectangle

Add the header and footer information and refer the hidden rectangle contained control informations(Using ReportItems("").Value ).

Kind Regards

Sundaraguru S