关于从Web Service中返回一个SqlConnection部件出错的问题,代码如下:
private SqlConnection Cn=null;
private SqlConnection AccCn=null;
[WebMethod]
public SqlConnection AppCn(String AccNo)
{
if (Cn != null)
return;// Cn;
if (AccNo == null)
{
SqlCommand com = new SqlCommand("select * from AppAccount Where AccNo='" + AccNo + "'", AccCn);
SqlDataReader mreader = com.ExecuteReader();
mreader.Read();
String Connect_Str = "Data Source=" + mreader["AccServer"].ToString() + ";Initial Catalog=" + mreader["AccDataBase"].ToString();
Connect_Str = Connect_Str + ";Persist Security Info=True;User ID=" + mreader["AccUser"].ToString() + ";Password=" + mreader["AccPassword"].ToString();
Cn = new SqlConnection(Connect_Str);
}
else
{
Cn = new SqlConnection();
Cn.ConnectionString = AccCn.ConnectionString;
}
Cn.Open();
return Cn;
}
错误:
Cannot serialize member System.ComponentModel.Component.Site of type System.ComponentModel.ISite because it is an interface.
该如何解决啊?
SqlConnection 不能被序列化,所以不能通过webservice 返回
