Showing posts with label proc. Show all posts
Showing posts with label proc. Show all posts

Sunday, March 11, 2012

CLR Stored Procedure is timing out

At one seemingly inoccuous step in my CLR stored procedure, execution stops and the query times-out.

I've tried debugging the stored proc by stepping into it from within VS. When I do, I get to the code in question, but then simply get this message:

WARNING: Debugger was accessing T-SQL variables while managed code was not suspended.
Waiting until the access is done to continue T-SQL execution.
Continueing T-SQL execution.


And these messages appear to repeat indefinitely. I'm running SQL Server locally on my machine, but this also happens on out development SQL Server server.

The place in the code it appears to happen is when returning back results from a lower-level CLR stored proc called within the higher-level CLR stored proc -- when piping the result set, I suppose.

I've set MAXDOP to 1. No help.

Anyone know what's going on?

Are the CPU and memory getting taken up more and more along with the message appears to repeat indefinitely?

Here is one thread with the same warning, it may be similar to your case:

http://forums.microsoft.com/technet/showpost.aspx?postid=780559&siteid=17

Suggest to move the thread to the forum .NET Framework inside SQL Server, there you will get rapid and qualified responses.

Thanks for your understanding!

CLR stored procedure

I got a problem with my CLR C# stored procedure. The proc have just one
param VARCHAR(8000) which I define in C# as String. Works fine until string
exceed 4000 bytes .
Instead of String I tryed SqlChars and SqlString - doesn't work.
In this case I get error "MDX statement was expected. An MDX expression was
specified."
Please help."Tim" <Tim@.discussions.microsoft.com> wrote in message
news:81C5DAC4-81EE-4688-92E9-968FA2F75F04@.microsoft.com...
>I got a problem with my CLR C# stored procedure. The proc have just one
> param VARCHAR(8000) which I define in C# as String. Works fine until
> string
> exceed 4000 bytes .
> Instead of String I tryed SqlChars and SqlString - doesn't work.
> In this case I get error "MDX statement was expected. An MDX expression
> was
> specified."
> Please help.
How about VARCHAR(MAX)?
David|||Try it too - same result.
Thanks.
"David Browne" wrote:

> "Tim" <Tim@.discussions.microsoft.com> wrote in message
> news:81C5DAC4-81EE-4688-92E9-968FA2F75F04@.microsoft.com...
> How about VARCHAR(MAX)?
> David
>
>|||This shouldn't be possible, if you tried to create your stored proc with
parameter varchar(8000) it would fail with the following error:
CREATE PROCEDURE for "MyStoredProc" failed because T-SQL and CLR types for
parameter "@.myparameter" do not match.
String parameters to CLR stored procs need to be nvarchar based because CLR
strings are all unicode, so to support strings larger than 4000 characters,
you'll need to use nvarchar(max).
Steven
"Tim" <Tim@.discussions.microsoft.com> wrote in message
news:81C5DAC4-81EE-4688-92E9-968FA2F75F04@.microsoft.com...
>I got a problem with my CLR C# stored procedure. The proc have just one
> param VARCHAR(8000) which I define in C# as String. Works fine until
> string
> exceed 4000 bytes .
> Instead of String I tryed SqlChars and SqlString - doesn't work.
> In this case I get error "MDX statement was expected. An MDX expression
> was
> specified."
> Please help.

CLR Stored Proc Queue activation help

I set up a queue to activate a clr stored procedure upon receiving a message and nothing is happening. I have tried everything listed in this topic:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=200684&SiteID=1

except for saying "Recieve Top(0)" which didn't make any sense to me. I have set the database to trustworthy (all of this is taking place within a single database on a local server). There are messages on the queue, and I have the queue activation set to max_queue_readers=2, procedure_name=StoredProcedure1, execute as owner. I tried execute as self and that didn't work either. I signed the assembly that contains StoredProcedure1 and the assembly that it references. The only thing that appears in the sql error log is this (I trimmed off the timestamp):

AppDomain 15 (TriggerTest.dbo[runtime].14) is marked for unload due to common language runtime (CLR) or security data definition language (DDL) operations.
AppDomain 15 (TriggerTest.dbo[runtime].14) unloaded.
AppDomain 18 (TriggerTest.dbo[runtime].17) created.

If I call the stored procedure manually it works just fine

I also tried signing the procedure (the t-sql stored proc that calls the clr proc) as described here:

http://blogs.msdn.com/remusrusanu/archive/2006/03/01/541882.aspx

Still no luck... The proc is never activated. The message sits in the queue until I manually retrieve it.

|||

If you issue an EXECUTE AS USER = 'nameofqueueowneruser'; followed by mannualy launching the procedure, do you get an error or is the procedure running fine?

Thanks,
~ Remus

|||The procedure runs fine when executed as you stated above.|||

Are you sure the queue activation is actually enabled? Activation can be set up (procedure name, max_queue_readers, execute as user) but the activation itself might be disabled. sys.service_queues.is_activation_enabled column will show this. If is disabled, then running ALTER QUEUE [queuename] WITH ACTIVATION (STATUS = ON) will enabled it. Note that the clause WITH ACTIVATION (STATUS = ON/OFF) is different from WITH STATUS = ON/OFF.

HTH,
~ Remus

|||Ok, apparently the procedure was running, it just wasn't retrieving the message from the queue. I changed the procedure to simply insert a row into a table and it did do that. Also, I set a breakpoint in the procedure, but VS2005 never stops. Now I need to figure out why it won't retrieve the message. Thanks for you help|||

How are you attempting to debug from Visual Studio?

For debugging, you need to attach to the sqlservr.exe process using remote debugger. We have tested that this works even for internally activated procedures.

Rushi

CLR Stored proc is timing out

At one seemingly inoccuous step in my CLR stored procedure, execution stops
and the query times-out.
I've tried debugging the stored proc by stepping into it from within VS.
When I do, I get to the code in question, but then simply get this message:
WARNING: Debugger was accessing T-SQL variables while managed code was not
suspended.
Waiting until the access is done to continue T-SQL execution.
Continueing T-SQL execution.
And these messages appear to repeat indefinitely. I'm running SQL Server
locally on my machine, but this also happens on out development SQL Server
server.
The place in the code it appears to happen is when returning back results
from a lower-level CLR stored proc called within the higher-level CLR stored
proc -- when piping the result set, I suppose.
I've set MAXDOP to 1. No help there.
Anyone know what's going on?Hello Quimbly,

> The place in the code it appears to happen is when returning back
> results from a lower-level CLR stored proc called within the
> higher-level CLR stored proc -- when piping the result set, I
> suppose.
Can you be a bit more specific about what you're doing?
Is your CLR proc calling another CLR proc without in parameter passed as
ref out out? How are you executing the other stored procedure.
Note: a better newsgroup for this would be Micorosoft.Public.SqlServer.CLR,
I've copied this there.
Thanks!
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/|||> Can you be a bit more specific about what you're doing?
The top-level CLR proc calls a regular static method in the SQL CLR project.
This static method makes a call to another SqlProcedure (static method
tagged with [Microsoft.SqlServer.Server.SqlProcedure] attribute).
The static method is calling the lower-level CLR proc as follows:
string sqlString = "LC_SP_ScheduleEvents_SelectForDate";
SqlCommand command = new SqlCommand(sqlString, connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@.P_LuminaireID", luminaireID);
command.Parameters.AddWithValue("@.P_TargetDate", usageDate);
command.Parameters.AddWithValue("@.P_TargetDateStartInUTC", startTimeUTC);
command.Parameters.AddWithValue("@.P_TargetDateEndInUTC", endTimeUTC);
SqlDataReader reader = command.ExecuteReader();
//...
Inside the LC_SP_ScheduleEvents_SelectForDate proc, it times out when it's
piping it's results back:
I.e.:
...
for (int i = 0; i < dr.Length; i++)
{
// send one event
eventRow = new SqlDataRecord(eventRowMetaData);
eventRow.SetSqlBoolean(0, bool.Parse(dr[i]["IsLampOn"].ToString()));
eventRow.SetSqlDateTime(1,
DateTime.Parse(dr[i]["ActualEventTime"].ToString()));
eventRow.SetInt32(2, int.Parse(dr[i]["DimmingLevel"].ToString()));
SqlContext.Pipe.SendResultsRow(eventRow);
}
}
SqlContext.Pipe.SendResultsEnd();|||Hello Quimbly,
I know this seems lame, but I suspect you have a reference type issue here.
Try assigning IsLampOn, ActualEventTime and DimmingLevel to local value type
s,
then sets those into the DataRecord.
Its low hanging fruit to solve first.
Thanks!
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/

CLR Stored proc is timing out

At one seemingly inoccuous step in my CLR stored procedure, execution stops
and the query times-out.
I've tried debugging the stored proc by stepping into it from within VS.
When I do, I get to the code in question, but then simply get this message:
WARNING: Debugger was accessing T-SQL variables while managed code was not
suspended.
Waiting until the access is done to continue T-SQL execution.
Continueing T-SQL execution.
And these messages appear to repeat indefinitely. I'm running SQL Server
locally on my machine, but this also happens on out development SQL Server
server.
The place in the code it appears to happen is when returning back results
from a lower-level CLR stored proc called within the higher-level CLR stored
proc -- when piping the result set, I suppose.
I've set MAXDOP to 1. No help there.
Anyone know what's going on?
Hello Quimbly,

> The place in the code it appears to happen is when returning back
> results from a lower-level CLR stored proc called within the
> higher-level CLR stored proc -- when piping the result set, I
> suppose.
Can you be a bit more specific about what you're doing?
Is your CLR proc calling another CLR proc without in parameter passed as
ref out out? How are you executing the other stored procedure.
Note: a better newsgroup for this would be Micorosoft.Public.SqlServer.CLR,
I've copied this there.
Thanks!
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/
|||> Can you be a bit more specific about what you're doing?
The top-level CLR proc calls a regular static method in the SQL CLR project.
This static method makes a call to another SqlProcedure (static method
tagged with [Microsoft.SqlServer.Server.SqlProcedure] attribute).
The static method is calling the lower-level CLR proc as follows:
string sqlString = "LC_SP_ScheduleEvents_SelectForDate";
SqlCommand command = new SqlCommand(sqlString, connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@.P_LuminaireID", luminaireID);
command.Parameters.AddWithValue("@.P_TargetDate", usageDate);
command.Parameters.AddWithValue("@.P_TargetDateStar tInUTC", startTimeUTC);
command.Parameters.AddWithValue("@.P_TargetDateEndI nUTC", endTimeUTC);
SqlDataReader reader = command.ExecuteReader();
//...
Inside the LC_SP_ScheduleEvents_SelectForDate proc, it times out when it's
piping it's results back:
I.e.:
...
for (int i = 0; i < dr.Length; i++)
{
// send one event
eventRow = new SqlDataRecord(eventRowMetaData);
eventRow.SetSqlBoolean(0, bool.Parse(dr[i]["IsLampOn"].ToString()));
eventRow.SetSqlDateTime(1,
DateTime.Parse(dr[i]["ActualEventTime"].ToString()));
eventRow.SetInt32(2, int.Parse(dr[i]["DimmingLevel"].ToString()));
SqlContext.Pipe.SendResultsRow(eventRow);
}
}
SqlContext.Pipe.SendResultsEnd();
|||Hello Quimbly,
I know this seems lame, but I suspect you have a reference type issue here.
Try assigning IsLampOn, ActualEventTime and DimmingLevel to local value types,
then sets those into the DataRecord.
Its low hanging fruit to solve first.
Thanks!
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/

CLR Stored proc is timing out

At one seemingly inoccuous step in my CLR stored procedure, execution stops
and the query times-out.
I've tried debugging the stored proc by stepping into it from within VS.
When I do, I get to the code in question, but then simply get this message:
WARNING: Debugger was accessing T-SQL variables while managed code was not
suspended.
Waiting until the access is done to continue T-SQL execution.
Continueing T-SQL execution.
And these messages appear to repeat indefinitely. I'm running SQL Server
locally on my machine, but this also happens on out development SQL Server
server.
The place in the code it appears to happen is when returning back results
from a lower-level CLR stored proc called within the higher-level CLR stored
proc -- when piping the result set, I suppose.
I've set MAXDOP to 1. No help there.
Anyone know what's going on?Hello Quimbly,
> The place in the code it appears to happen is when returning back
> results from a lower-level CLR stored proc called within the
> higher-level CLR stored proc -- when piping the result set, I
> suppose.
Can you be a bit more specific about what you're doing?
Is your CLR proc calling another CLR proc without in parameter passed as
ref out out? How are you executing the other stored procedure.
Note: a better newsgroup for this would be Micorosoft.Public.SqlServer.CLR,
I've copied this there.
Thanks!
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/|||> Can you be a bit more specific about what you're doing?
The top-level CLR proc calls a regular static method in the SQL CLR project.
This static method makes a call to another SqlProcedure (static method
tagged with [Microsoft.SqlServer.Server.SqlProcedure] attribute).
The static method is calling the lower-level CLR proc as follows:
string sqlString = "LC_SP_ScheduleEvents_SelectForDate";
SqlCommand command = new SqlCommand(sqlString, connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@.P_LuminaireID", luminaireID);
command.Parameters.AddWithValue("@.P_TargetDate", usageDate);
command.Parameters.AddWithValue("@.P_TargetDateStartInUTC", startTimeUTC);
command.Parameters.AddWithValue("@.P_TargetDateEndInUTC", endTimeUTC);
SqlDataReader reader = command.ExecuteReader();
//...
Inside the LC_SP_ScheduleEvents_SelectForDate proc, it times out when it's
piping it's results back:
I.e.:
...
for (int i = 0; i < dr.Length; i++)
{
// send one event
eventRow = new SqlDataRecord(eventRowMetaData);
eventRow.SetSqlBoolean(0, bool.Parse(dr[i]["IsLampOn"].ToString()));
eventRow.SetSqlDateTime(1,
DateTime.Parse(dr[i]["ActualEventTime"].ToString()));
eventRow.SetInt32(2, int.Parse(dr[i]["DimmingLevel"].ToString()));
SqlContext.Pipe.SendResultsRow(eventRow);
}
}
SqlContext.Pipe.SendResultsEnd();

CLR SP and config file

Can a clr stored proc use a config file?Technically it works, but its not recommended or officially supported.
Reference:
d286" target="_blank">http://www.sqlskills.com/blogs/bobb...e55
d286
and
e81d" target="_blank">http://www.sqlskills.com/blogs/bobb...7d1
e81d
Cheers,
Bob Beauchemin
http://www.sqlskills.com/blogs/bobb
"Richard" <napa299@.yahoo.com> wrote in message
news:OLUWTkmlGHA.1552@.TK2MSFTNGP04.phx.gbl...
> Can a clr stored proc use a config file?
>