The connection is already Open (state=Open)". when it goes to SaveTOSQL.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Guys
I tried to insert data into SQL server database using the following code. All data that I received from all my connections (10 socket). It runs for sometime It was able to insert some data then suddenly in the middle of the process I encountered
"The connection is already Open (state=Open)". when it goes to SaveTOSQL
I declare my DBConnect as modular and with CONNECTION POOLING

//DBConnect = new SqlConnection("Pooling=true;server=OSSSQL01;database=nfmse;uid=alarmadmin;pwd=alarmadm1n;Min Pool Size=3;Max Pool Size=100;")

Processdata(

iRx = theSockId.thisSocket.EndReceive (asyn)
char[] chars = new char[iRx]; // + 1]
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder()
int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0)
StringBuilder szData = new StringBuilder()
szData.Append(chars)
DBConnect.Open()
SaveTOSQL()


void SaveTOSQL(

string strInsert = "insert into rop values ('" + strjv.Trim() + "','" + strdate.Trim() + "','" + strclass.Trim() + "','" + strFile + "','" + strFile + "')"

DBCommand = new SqlCommand(strInsert,DBConnect)
DBCommand.ExecuteNonQuery()


PS : I don't close the connection nor the command becuase this is a 24 hour process

Thanks in advance
/dabsukol
 
You should really create a connection per operation instead of using the
same one and run into thread access issues.
There is almost no time penality in this way, since ado.net uses connection
pooling.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

dabuskol said:
Hi Guys,
I tried to insert data into SQL server database using the following code.
All data that I received from all my connections (10 socket). It runs for
sometime It was able to insert some data then suddenly in the middle of the
process I encountered
"The connection is already Open (state=Open)". when it goes to SaveTOSQL.
I declare my DBConnect as modular and with CONNECTION POOLING.

//DBConnect = new
SqlConnection("Pooling=true;server=OSSSQL01;database=nfmse;uid=alarmadmin;pw
d=alarmadm1n;Min Pool Size=3;Max Pool Size=100;");
Processdata()
{
iRx = theSockId.thisSocket.EndReceive (asyn);
char[] chars = new char[iRx]; // + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
StringBuilder szData = new StringBuilder();
szData.Append(chars);
DBConnect.Open();
SaveTOSQL();
}

void SaveTOSQL()
{
string strInsert = "insert into rop values ('" + strjv.Trim() + "','" +
strdate.Trim() + "','" + strclass.Trim() + "','" + strFile + "','" + strFile
+ "')" ;
 
Back
Top