Activated Stores Procedure And Batch Processing

Aug 2, 2006

Hi There

2 Questions :

1. Almost in every SB example you will see this sql :

BEGIN TRANSACTION

WAITFOR (

RECEIVE TOP (1)

@MessageType = message_type_name,

@Message = message_body

FROM [Queue1]

WHERE conversation_handle = @ConversationHandle

), timeout 5000;

If this sql in an activated sp do you really have to have the waitfor ? Since the sp will only be fired if there is a message on the queue ?

2. It is reccomended that for high volume SB apps you do not do a top(1) receive but process batches. Exactly what is the best practice to do this. Receive a batch into a table variable and then what ? Process through it with a cursor ? That is not very efficient either, i would just like some insight into batch queue processing as everywhere i have seen uses top (1) from the queue ?

Thanx

View 3 Replies


ADVERTISEMENT

Why Does The Condition Activated = Isnull(@activated, -1) Work?

Jul 16, 2005

I have a stored procedure into which a bit type of parameter called '@activated' is being passed. This stored procedure gets all the users matching the condition :
Activated = isnull(@activated, -1)

In users table, one of the columns is 'Activated' of bit type.
The strange thing happening here is that if @activated is null, then the above condition is true for all rows in users table, even though we know that the column Activation  is either 1 or 0 only and never -1.Can someone explain why this strange thing is happening?

View 2 Replies View Related

Osql Batch Processing Without -i

Jan 17, 2006

Hi,I have just started using MSSQL and the DOS environment at work. I havea lot of experience with Sybase and the UNIX environment, but this is awhole new ball of wax.I'd like to use osql from a batch file to log into the dataserver andrun a fairly long list of SQL and then exit. I don't want to have a bunchof SQL files sitting around that I have to use the -i option to run, andI'd rather not create temporary SQL files like this.echo "exec sp_who2" >tmp.sqlecho "select * from....... " >>tmp.sqlosql -E -S <DATASERVER> -n -w999 -i tmp.sqldel tmp.sqlI can't use the -Q option, of course because as I said, I'll be writingquite a few lines of SQL, and it won't all fit on the one line, or at leastit wouldn't be pretty if I did.In UNIX, I can simply execute the following from either the command lineor ina script.isql -S<DATASERVER> -U<USER> <<-EOFsp_whogoselect * from .....goEOF --EOF is the isql session terminator exits me back to the command line.This behavior does not appear to work with OSQL. There is a -O optionwhich help mentions, and that talks about disabling the EOF terminator forbatch processing, but I wasn't able to find any usage or examples on the netwhere someone is using EOF to terminate their OSQL SQL batch.This is what help listed.[-O use Old ISQL behavior disables the following]<EOF> batch processingAuto console width scalingWide messagesdefault errorlevel is -1 vs 1Any help you could offer would be appreciated. Thanks.Darren

View 2 Replies View Related

Stored Procedure Activated More Than Once

Nov 23, 2006

Hi guys!

Is it possible for a stored procedure to be activated more than once even if a message is sent only once? After sending the message, I check the sys.dm_broker_activated_tasks and see that it activates more than once. Is there a way for me to prevent this from happening?

Thanks a lot! :)

View 4 Replies View Related

Stores Procedure

May 5, 2005

I am trying to select the HdwId value of a table named "tblHdw" and trying to insert it into the HwdId field in a table named "tblLoc". 

If you have any suggestions?

Thanks,
MattyPee

View 1 Replies View Related

Use VB DLL In A Stores Procedure?

Feb 14, 1999

I read in a technical journal (somewhere) that it is possible to create a ActiveX DLL in Visual Basic and use the DLL in a stored procedure. There were some limitations (because of stored procedures) but this is still a very powerful feature. Has anyone ever heard of this or read about this? Is there s source for explanation and examples?

Thanks, Rich.

View 1 Replies View Related

How To Launch MSOLAP Cube Processing In Batch Mode?

Mar 12, 2001

Jonathan Yang Jonathan.Yang@Weyerhaeuser.Com

How to launch MSOLAP cube processing in batch mode?
================================================== =

When one wants to run SQL Statement or Stored procedure in batch mode, OSQL.exe can be used.

Now we have created OLAP cube and want to process(populate) cube. From MSOLAP Analysis manage we can right click a cube name then click “Process”. But how to do this in batch mode? I.e. any equivalent thing of OSQL.exe to help process cube?

I believe a matured tool should work good in both interactive and batch mode. Unfortunately I did not find how to launch cube processing from MS OLAP documents. Looks like we have to write one using DSO supplied by Microsoft. Do you know if there is any tool for us not to write one? Pls help.

View 1 Replies View Related

Cannot Debug Activated CLR Stored Procedure

Jan 11, 2007

Hi

I'm having a problem debugging (with VS2005,) a CLR Stored Procedure which is activated on a queue. I know it is working because it is consuming and processing messages when one appears in the queue.

I can debug it 'manually' by either right-clicking on the SP within VS2005 and selecting 'Step into Stored Procedure' or by attaching to the SQL Server Management Studio process, setting a breakpoint and executing the stored procedure from a Management Studio query window.

However, if I send a message to my queue within Management Studio, my breakpoints are NOT being hit within VS2005, but the message IS reaching my queue and it IS being processed by the SP.

Can anyone help?

Thanks

View 3 Replies View Related

Set New_broker When The Activated Stored Procedure Changes.

Sep 4, 2007

Hi I have a couple of questions to understand better Service Broker..

Every time I alter the activation Stored Procedure on the receiving queue I also execute the:
alter database set new_broker rollback

1) can somebody explain me in a detailed way why I have to do that? what happen inside SQL Server when there is a Stored Procedure activated on a queue??
Also link to white papers, resouces on so on are appreciated.

My Activation Stored Procedure calls other stored procedure.
2) If ONLY one of the nested stored procedures changes I have to execute the command:
alter database set new_broker rollback ???

I think that the answer to the first question will answer the second one..

Thank you for any helps!
Marina B.

View 3 Replies View Related

Ending A Conversation In A CLR Activated Stored Procedure

Apr 26, 2006

I've read Remus' article on Fire and Forget tactics when it comes to ending conversations, and I have to admit I am guilty of sending a message to a service and immediately ending the conversation. I've set up a stored procedure to end the conversation on the initiator queue, but I'm guessing it's never being fired because I am not ending the conversation in the target activated stored proc, which is a CLR stored proc.

Can you tell me how to end the conversation from a CLR stored proc?

Now that I think of it none of the code I use in my TSQL activated stored procs to handle different message types and error-checking is done in the CLR stored proc.

Thanks

View 5 Replies View Related

Returing ADO Recordset From Stores Procedure

Nov 24, 2003

I have a Stored Procedure that I am calling from ADO 2.7 in Visual Basic. The process works fine when the stored procedure has records to return. However , when the recordset is return emtpy ADO does not recognize the recordset as being open and empty. For example:
VB Code to open recordset:
Set rstClass1 = New ADODB.Recordset
With rstClass1
.CursorLocation = adUseServer
Set .ActiveConnection = DBConn
.Source = strRecordSource
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
If Not .EOF Or Not .BOF Then

The program bombs on the If Not .EOF statement with Error 3704 -
"Operation is not allowed when the object is closed.


When I run the Stored Procedure In QA using an ID that I know will NOT return any records the result window returns nothing. I noticed that on some of my other SP's the result window will at least return the column titles. These SP's also do not produce the 3704 error in ADO.

Is there a command or a certain method to construct my SP so that is will return enough for ADO to know that the recordset did open its just empty?

The SP is ugly looking but I will post if need be.

View 3 Replies View Related

Event Notifications Don't Fire When Raised By Activated Procedure

Oct 23, 2006

I have an activated SP that is issuing PRINT statements.

These are raised as ErrorLog and EventLog events when using SQLProfiler

However if you attach an event notification for ERRORLOG and EVENTLOG, nothing appears in the queue. Any other ERRORLOG or EVENTLOG event caught by profiler is caught by the event notification as expected.

View 2 Replies View Related

Pass Sorting Parameter To Stores Procedure

Feb 23, 2004

I used Datagrid to show "Title", "Location" and "Date", It works very well.
I want to sort DataGrid data, that is when user click the "Title", "Location" or "Date",
my asp.net code will through class and send "Sort" parameter to stores procedure to get the new data and bind to DataGrid.

Here is my stores procedure:

CREATE Procedure JobSearch
(
@Search varchar(150),
@Sort varchar(50)
)
AS

SELECT
JobTitle,
JobLocationCity,
JobLocationState,
PostDate

FROM
Job

WHERE
JobTitle LIKE '%' + @Search + '%'
OR
JobKeywords LIKE '%' + @Search + '%'

IF @Sort = "Title"
ORDER BY JobTitle
IF @Sort = "Location"
ORDER BY JobLocationState, JobLocationCity
IF @Sort = "PostDate"
ORDER BY PostDate DESC

When I test stores procedure in SQL Server, I got the error about "Error 156: Incorrect syntax near the keyword 'ORDER' ".

Who has experience about stores procedure, please help me to correct this error.

View 12 Replies View Related

Stores Procedure - Must Declare Scalar Variable

Apr 7, 2015

I am creating a SP below and it keep saying must declare scalar variable @comments,I have already declared @comments varchar (255)

error---> (Msg 137, Level 15, State 2, Procedure CheckPatientComments, Line 26
Must declare the scalar variable "@commnets".
)

quote:
CREATE PROCEDURE [dbo].[CheckPatientComments] (@enc_id varchar(36) OUTPUT, @data_ind CHAR(1) OUTPUT)
AS
BEGIN
DECLARE
@comments varchar(255)

[code]....

View 2 Replies View Related

Service Broker Activated Procedure Getting Deadlock While Running Mulitple Queue_reader Threads

Mar 7, 2008

Hi,

I am getting deadlock on activated procedure which I am using to receive message from the Service Broker Queue.

Deadlock details:

Two threads are tring to do delete on internal table queue_messages_122847900 ends up in a dead lock.

Activated procedure code

RECEIVE TOP(1) @xmlMessage = message_body,
@handle = conversation_handle,
@message_type = message_type_name
FROM TransactionQueue;

IF (@message_type = 'http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog')
BEGIN
END CONVERSATION @handle;
RETURN 0
END
.........................
.........................
After this I do process the message and some other processing

And then

END CONVERSATION @handle;

Note I do have single conversation group

Is their a problem in the way I am receiving and processing messages. Is it possible because of the delay between RECEIVE and END CONVERSATION same message is read by two different threads.

Thanks

View 1 Replies View Related

Conversation Handle Processed By An Activated Stored Procedure Service Can Not Be Invoked By A CLR Service Instance?

Dec 1, 2006

I have a initiator and a target service broker peer.

Both are controlled by a C# unit test. The initiator uses the Microsoft.Samples.SqlServer class. The target service uses stored procedure activation.

Sending a message from the initiator to the target, saves the content of the message, along with its conversation handle in the target's database specific table.

The unit test needs - at a later time - to instruct the target to send a message back on the same conversation handle to the initiator service.

For this the C# unit test creates a Conversation off of the saved conversation handle:


Service client = new Service("cleintservicename", conn, tran);

Conversation dialog = null;

dialog = new Conversation(client, convHandle);
Sending the message on this dialog generates an error "Message body: <Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"><Code>-8495</Code><Description>The conversation has already been acknowledged by another instance of this service.</Description></Error>".
Is the error due to the fact that a service - using the activated stored procedure already picked up the conversation, so that a new reference to the service can not be created through the Service class in CLR?
If so, I might need then to skip the activated stored procedure in favor or a CLR service, alltogether?
Any help - greatly appreciated.

View 7 Replies View Related

TSQL + VBA Excel 2003 - Importing Data From MS Excel 2003 To SQL SERVER 2000 Using Multi - Batch Processing

Sep 11, 2007

Hi,
I need to import an SQL string from MS Excel 2003 to SQL SERVER 2000.
The string I need to import is composed by 5 different several blocks and looks like:



Code Snippet

CommandLine01 = "USE mydb"
CommandLine02 = "SELECT Block ..."
CommandLine03 = "GO
ALTER TABLE Block...
GO"
CommandLine04 = "UPDATE Block..."
CommandLine05 = "SELECT Block..."

The detail of the SQL string is at:
http://forums.microsoft.com/msdn/showpost.aspx?postid=2093921&siteid=1&sb=0&d=1&at=7&ft=11&tf=0&pageid=1



I am trying to implement OJ's suggestion:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2117223&SiteID=1
to use multi - batch processing to import the string to SQL SERVER, something like:




Code Snippet
Dim SqlCnt, cmd1, cmd2, cmd3
'set the properties and open a connection

cmd1="use my_db"
cmd2="create table mytb"
cmd3="insert into mytb"

SqlCnt.execute cmd1
SqlCnt.Execute cmd2
SqlCnt.Execute cmd3

Below is the code (just partial) I have, and I need help to complete it.
Thanks in advance,
Aldo.




Code Snippet
Function TestConnection()
Dim ConnectionString As New ADODB.Connection
Dim RecordSet As New ADODB.RecordSet

ConnectionString = "Driver={SQL Server};Server=myServer;Database=myDBName;Uid=UserName;Pwd=Password"
ConnectionString.Open

CmdLine01 = " USE " & myDB
CmdLine02 = " SELECT ACCOUNTS.FULLNAME FROM ACCOUNTS" ...

CmdLine03 = "GO
ALTER TABLE Block...
GO"

CmdLine04 = "UPDATE Block..."
CmdLine05 = "SELECT Block..."

RecordSet.Open CmdLine01, ConnectionString
RecordSet.Open CmdLine02, ConnectionString

ConnectionString.Execute CmdLine01
ConnectionString.Execute CmdLine02

'Retrieve Field titles
For ColNr = 1 To RecordSet.Fields.Count
ActiveSheet.Cells(1, ColNr).Value = RecordSet.Fields(ColNr - 1).Name
Next

ActiveSheet.Cells(2, 1).CopyFromRecordset RecordSet

'Close ADO objects
RecordSet.Close
ConnectionString.Close
Set RecordSet = Nothing
Set ConnectionString = Nothing

End Function






View 7 Replies View Related

Batch Procedure

Apr 21, 2006

Dear friends

I want to be able to make a batch that adds a column to every table in one go


Find a table object
Attach table name to columnname called "Concurrency"
Add column called Concurrency timestamp
If present already, don’t do it

Anyway to do it or do I have to do it manually?

cm

View 3 Replies View Related

Batch Update In Stored Procedure

Feb 26, 2004

The following code is a part of my stored procedure MySP. I would like to update Users table with input variable @userIDs which has the following format:

101, 102, 103

I got the error message:

Syntax error converting the varchar value '101, 102, 103' to a column of data type int.

Obviously, UserID has datatype int. How can I write this SP?


CREATE PROCEDURE dbo.MySP
@userIDs varchar(100)
AS
SET NOCOUNT ON

BEGIN TRANSACTION

UPDATE Users SET IsActive = 1 WHERE UserID IN (@userIDs)

IF @@ERROR <> 0
ROLLBACK TRANSACTION
ELSE
COMMIT TRANSACTION

SET NOCOUNT OFF

View 8 Replies View Related

Processing Data From Stored Procedure

Aug 22, 2001

I want to capture and process data inside of a stored procedure by executing another stored procedure. If proc1 calls proc2 and proc2 returns 1 or more rows, consisting of 2 or more columns, what is the best way to do this?

Currently, I know I'm returning 1 row of 3 columns, so I concatenate the data and either return it with an OUTPUT parameter or using the RETURN stmt.

TIA,
mike

View 1 Replies View Related

Parameters Processing Within Stored Procedure

Jun 30, 1999

I want to create a stored procedure that can have up to 20+ parameters. Then I want to be able to access those parameters within a while loop by iteratating through the values without using the specific parameter name.
example: @parm(x) where x = a subscript value.

Any suggestions?

Thanks in advance!
Sidney Ives

View 2 Replies View Related

Running A Batch File From A Stored Procedure

Jun 27, 2001

Is there a way to run/call a batch file from a stored procedure?

Or, is there a way to run/call a batch file from a trigger?

View 2 Replies View Related

Execute Stored Procedure Via Batch File

Jan 20, 2012

I have a stored procedure that generates some data and dumps it into a table. I need to export data using bcp based on the data that this procedure creates. So I know how to use bcp but don't know how to execute the procedure and pass it the two variables that it needs. I googled it and sqlcmd looks promising but can get the syntax right. The two variables are the current year and school number ie. 1112, 0021.

View 3 Replies View Related

Transact SQL :: Difference Between Batch And Stored Procedure?

Jun 19, 2015

What is the difference between Batch and Stored Procedure?

View 5 Replies View Related

SQL Search :: Catching Batch ID From Running Stored Procedure

May 5, 2015

how to catch batch id from a running stored procedure. My intention is that when we run store procedures in batch we are running a lot of procedures and I would like to log each run and if the same procedure is running several times per day I need to separate the runs by a "batch id" for the specific run. I have created a logtable and a logprocedure that logs the start and end of a procedure run and also some values for the run. So I'm trying to find a way of fetching the "batch id" that the sp is running so I can separate the runs when analyzing the logtable. I have looked at metadata tables and also in the table sys.sysprocesses but I cannot find BATCH ID.

View 11 Replies View Related

Variable Names Must Be Unique Within A Query Batch Or Stored Procedure.

May 4, 2007

hi ,

i got this error ... i have tried various scenarios.. nothing works for me... can any one gimme the proper guidance...



The variable name '@CCSID' has already been declared. Variable names must be unique within a query batch or stored procedure.

thanx in advance

raj

View 5 Replies View Related

Continue Processing Stored Procedure, When A Failure Occurs...

Apr 8, 1999

All,
Is there a way, in SQL Server 6.5, to continue processing within a stored procedure even though an error occurs? An example I am inserting records into a temp table within a stored procedure, and there may be duplicate UNIQUE keys, I simply want the procedure to continue inserting records ignoring the failure.

Thank you,
Scott Kolek
Development Manager

SKM Software
http://www.skm-software.com

View 3 Replies View Related

C# Stored Procedure Processing Binary Data To Sql Fields

Jul 25, 2007





In the code sample below, case eLABEL, eENGUNITS works ok. The target SQL field is defined as varchar(50).

The second section is not so happy. It is attempting to write to an SQL field defined as binary(2)



Executing an SQL script to excercise this line results in error:


System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'foreign'

where 'foreign' is the name (FieldDef.sFldName) of the SQL field being written.



The c# code composes the following command:



"UPDATE " + acPointType + " SET " + FieldDef.sFldName +

" = @data_params WHERE VEC = '" + acVECName +

"' and name = '" + acPointName + "';";
What is the proper syntax for the second case set?






Code Snippet

case vcidatatype.eLABEL:

case vcidatatype.eENGUNITS:

{


byte[] bbuff = new byte[512];

bbuff = rdr.ReadBytes(FieldDef.iLen);

vciSqlCommand.Parameters.Add(new SqlParameter("@data_params", SqlDbType.VarBinary));

vciSqlCommand.Parameters["@data_params"].Value = bbuff;

break;

}

case vcidatatype.eFIDADR:

case vcidatatype.eLANADR:

{


byte[] bbuf = new byte[512] ;

bbuf = rdr.ReadBytes(2);

vciSqlCommand.Parameters.Add(new SqlParameter("@data_params", SqlDbType.Binary));

vciSqlCommand.Parameters["@data_params"].Value = bbuf;

break;
}





















View 1 Replies View Related

SQL Server 2008 :: Running Batch File To Execute A Stored Procedure

May 11, 2015

I have create a batch file to execute a stored proc to import data.

When I run it from the server (Remote Desktop) it works fine, but if I share the folder and try to run it from my pc, it doesn't do anything. I don't get an error, it just doesn't do anything. My windows user has admin rights in SQL. Why is it not executing from my PC?

View 9 Replies View Related

Stored Procedure And Function To Add Hashbyte (chksum) To Be Able To Do Delta Processing

Feb 5, 2015

function

/*Title:
Created By:
Create Date:
Notes:This function is used to concatenate the fields of a table except any identity and hashbyte column passed into the function. It works for temp tables are phyisical tables.

** NOTE: The temp table has be on the same SQL connection to work. If you use this in SSIS you will need to make your connection persistant.

The original concept came from [URL] .... and was modified.

Revisions:

*/
ALTER FUNCTION [dbo].[get_hash_fields] ( @p_table_name VARCHAR(128),
@p_schema_name VARCHAR(20),
@chksum_col_name varchar(255) )
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @sqlString as varchar(max)

[Code] ....

View 0 Replies View Related

Activated Proc Not Firing.

Mar 13, 2007

Hi There

I just had the following scenario.

I checked sys.service_queues to confirm the my queue has an activated proc assigned to it and is activation_enabled.

I send messages to the service, however i see that the messages just sit in the queue. I run profiler with all SB and Error events there is nothing, i check the sql server log, there is also nothing.

So i have no idea why the activated proc is not firing, all i see in the profiler trace is that the messages are acknowledged but the activated proc does not execute.

For a while i was stumped. i then tried to execute the proc myself and i got a syntax error.

Basically what happened was that i altered a table that the proc used and now the proc cannot execute cos there are more columns that must be inserted so i altered the proc.

However the activated proc still did not fire.

I had to disable and re-enable activation for it to work.

What i am wondering is why was there no indication in profiler or the sql og as the the fact that something was wrong with the activated proc ? Surely the activated proc should have fired and given the same error i got either to the sql log or profiler ?

And why did i have to re-enable activation ? Does sql cache the proc when you activate it and not know that the proc has changed when you alter it ?

Thanx

View 4 Replies View Related

Identify Queue That Activated Sp ?

Sep 10, 2006

Hi there

I have multiple queues with the same activated stored procedure (for various reasons we are trying this scenario).

My biggest obsticle is i cannot figure out a way to determine with the activated sp which queue caused it to activate.

Basically i need to make the sp dynamic, so that no matter which queue activated the sp the sp can determine the queue name and use that dynamically to do the receive command from the right queue.

I am sure it is possible since sys.dm_broker_activated_tasks shows how many sp's are activated by each queue, however the sp name is the same for all queues so that does not help me.

How do i determine within an activated sp which queue caused it to activate?

Thanx

View 1 Replies View Related

User List With First Activated Offer

Nov 27, 2013

I have 3 tables, please find the table structure and sample data below

Table 1 : tblUserInfo

UserID | FirstName | Email | JoinedDate

1 Testuser01 User01@User.com 10-10-2013
2 Testuser10 User10@User.com 11-10-2013
3 Testuser20 User10@User.com 11-10-2013

Table 2 : tblOffers

OfferID | OfferName | ExpiryDate

1 OfferSample1 15-10-2014
2 OfferSample2 15-9-2014
3 OfferSample3 10-07-2014

Table 3 :tblOfferActivated

ActivationID | UserID | OfferID | ActivationCode | ActivatedDate

1 2 3 ABC 11-11-2013
2 2 1 CEG 13-11-2013
3 3 1 JHG 18-11-2013
4 3 2 KIU 20-11-2013

Expected Output

I want to list out the users with the first activated offer details.The OfferName Should be based on the first activated date

UserID | FirstName | Email | JoinedDate | OfferID | OfferName |ActivatedDate | ActivationCode

1 Testuser01 User01@User.com 10-10-2013 Null Null Null Null
2 Testuser10 User10@User.com 11-10-2013 3 OfferSample2 11-11-2013 ABC
3 Testuser20 User10@User.com 11-10-2013 4 offerSample3 18-11-2013 JHG

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved