Difficulty connecting to local SQL Server Database

I've been having grave difficulty setting up and accessing stored procedures from a local SQL server database. A summary of relevant code is as follows.

static System.Data.SqlClient.SqlConnection _connection = new System.Data.SqlClient.SqlConnection();

public static void Deploy(Dictionary<string, object> parameters)
{
string connectstring = DEFAULTPARAMVAL;

if (parameters.ContainsKey("ConnectionStringOptions"))
{
connectstring = (string)parameters["ConnectionStringOptions"];
}

_connection.ConnectionString = connectstring;
_connection.Open();
}

The function I am implementing looks like the following:
public virtual int TagContained(string rfid)
{
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
command.Connection = _connection ;
command.CommandText = "dbo.TagContained" ;
command.CommandType = System.Data.CommandType.StoredProcedure ;
command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, 10, 0, null, System.Data.DataRowVersion.Current, false, null, "", "", ""));
command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@idnum", System.Data.SqlDbType.NVarChar, 1000, System.Data.ParameterDirection.Input, 0, 0, null, System.Data.DataRowVersion.Current, false, null, "", "", ""));
try
{
command.Parameters[1].Value = ((string)(rfid));
}
catch (Exception E)
{
LogMessage("Error in CommandCollection initialization: " + E.Message, Level.Error);
}
System.Data.ConnectionState previousConnectionState = command.Connection.State;
int returnValue = 0;
try
{
returnValue = (int)command.ExecuteNonQuery();
}
catch (Exception E)
{
LogMessage("Error in executing query: " + E.Message, Level.Error);
}
return returnValue ;
}

I get an assortment of the following errors in the process log:

73| Error|072007 13:29:55|Error in opening connection: The connection was not closed. The connection's current state is connecting.|[MyEventHandler]

97| Error|072007 13:29:55|Exception in ProcessTagReadEvent()->Evaluation: Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.|[MyEventHandler]

Furthermore, when I try to stop the process, the following error pops up after lagging in the "Action" status window
This request operation sent to net.tcp://a52--mxd5040280:7891/rfid/service/ProcessManager did not receive a reply within the configured timeout (00:01:00). The time allotted to this operation may have been a portion of a longer timeout. This may be because the service is still processing the operation or because the service was unable to send a reply message. Please consider increasing the operation timeout (by casting the channel/proxy to IContextChannel and setting the OperationTimeout property) and ensure that the service is able to connect to the client.

at Microsoft.SensorServices.Rfid.Management.ProxyBase.CallMethod(String methodName, Object[] args)
at Microsoft.SensorServices.Rfid.Management.ProcessManagerProxy.StopProcess(String processName, Boolean continueEventCollection)
at Microsoft.RadioFrequencyIdentification.Tools.ProcessNode.OnSyncAction(SyncAction action, SyncStatus status)


[6811 byte] By [VishalKumar] at [2008-2-23]
# 1

Hi Vishal

I am not going to look at your SQL problem, but I thought I would ask a clarifying question

Have you successfully run a AcmeEndtoEnd?

To run a successful AcmeEndtoEnd, here is what you do

From command prompt, navigate to c:\Program Files\Microsoft BizTalk RFID\Samples\Device Service Provider\Acme\AcmeEndtoEnd.

Launch acmesetup.cmd

From command prompt, navigate to c:\Program Files\Microsoft BizTalk RFID\Samples\Device Service Provider\Acme\AcmeEndtoEnd\AcmeDeviceSimulator

Launch runacmesimulator.cmd.

With RFID Manager, please check that the AcmeTestProcess is receivign tags correctly. Also, please check in SQL that the TagEvents table in rfidsink daatabase is getting events.

if you have already done all of this and it has worked successfully, please let us know.

-krish
KrishGopalan-MSFT at 2007-10-2 > top of Msdn Tech,BizTalk Server,BizTalk RFID...
# 2

Vishal,

You are doing connection.Open in the deploy. Deploy is not the place for this. Deploy method is like a setup for your event handler. You should probably override Init and put this code there. Init is executed once everytime your process engine is started. But, for connection I would encourage the following pattern (pseudo code)

using (connection.Open())

{

}

The idea is the sql connection is opened when you need it, and closed right away. You do not do connection pooling by opening the connection in Init. ADO.Net already does connection pooling for you. I think most of your errors will go away once you shift to this model.

Janakiram[MSFT] at 2007-10-2 > top of Msdn Tech,BizTalk Server,BizTalk RFID...