The connection is not open.
--------------------编程问答-------------------- DefSqlCon.open() --------------------编程问答-------------------- ...DefSqlCon.open()
[WebMethod]
public string InsertData(string newid title content)
{
try
{
string result = "";
string sql = "insert into t1(newid title) values ('" + newid + "','" + title + "')";
string sql1 = "insert into t2(newid content) values ('" + newid + "','" + content + "')";
MySqlConnection DefSqlCon = new MySqlConnection("server=192.168.0.1;user id=net;password=123;database=test");
MySqlCommand sqlcmd = new MySqlCommand(sql, DefSqlCon);
sqlcmd.Transaction = tran;
sqlcmd.Connection = DefSqlCon;
sqlcmd.ExecuteNonQuery();
MySqlCommand sqlcmd1 = new MySqlCommand(sql1, DefSqlCon);
sqlcmd1.Transaction = tran;
sqlcmd1.Connection = DefSqlCon;
sqlcmd1.ExecuteNonQuery();
tran.Commit();
result = "1";
return result;
}
catch (Exception err)
{
return err.ToString();
}
finally
{
}
MySqlCommand sqlcmd = new MySqlCommand(sql, DefSqlCon);
sqlcmd.Transaction = tran;
--------------------编程问答--------------------
[WebMethod]
public string InsertData(string newid title content)
{
try
{
string result = "";
string sql = "insert into t1(newid title) values ('" + newid + "','" + title + "')";
string sql1 = "insert into t2(newid content) values ('" + newid + "','" + content + "')";
MySqlConnection DefSqlCon = new MySqlConnection("server=192.168.0.1;user id=net;password=123;database=test");
MySqlCommand sqlcmd = new MySqlCommand(sql, DefSqlCon);
sqlcmd.Transaction = tran;
sqlcmd.Connection = DefSqlCon;
sqlcmd.ExecuteNonQuery();
MySqlCommand sqlcmd1 = new MySqlCommand(sql1, DefSqlCon);
sqlcmd1.Transaction = tran;
sqlcmd1.Connection = DefSqlCon;
DefSqlCon.Open();
sqlcmd1.ExecuteNonQuery();
tran.Commit();
result = "1";
return result;
}
catch (Exception err)
{
return err.ToString();
}
finally
{
}
--------------------编程问答-------------------- DefSqlCon.open()
连接没有打开 --------------------编程问答-------------------- 打开了也不行啊 --------------------编程问答-------------------- <?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://tempuri.org/">System.InvalidOperationException: The connection is not open. 在 MySql.Data.MySqlClient.MySqlConnection.BeginTransaction(IsolationLevel iso) 在 MySql.Data.MySqlClient.MySqlConnection.BeginTransaction() 在 WebService.InsertData
补充:.NET技术 , ASP.NET