貌似网上搜索到的范例和帮助文件里带的范例都是包含的,例如:[Microsoft.SqlServer.Server.SqlProcedure]
public static void getdata(SqlConnection conn)
{
SqlPipe sp = SqlContext.Pipe;
using (conn)
{
// conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
// cmd.Connection = conn;
cmd.CommandText = "Select * from price where name='book1'";
SqlDataReader rdr = cmd.ExecuteReader();
sp.Send(rdr);
}
}这样会不会造成运行一次存储过程就建立一次连接?批量读取数据的时候会很慢吧。
我把conn.open等语句在存储过程中去掉后,运行存储过程会提示
.NET Framework 错误:
System.InvalidOperationException: ExecuteReader: Connection property has not been initialized.就算我在程序里写了连接数据库的代码也一样
SqlConnection sqlcon = new SqlConnection(str); //连接新数据库
sqlcon.Open(); SqlCommand aCommand = new SqlCommand("getdata", sqlcon);
aCommand.CommandType = CommandType.StoredProcedure;
aCommand.ExecuteNonQuery();
该怎样把sqlcon传递给CLR存储过程呢
public static void getdata(SqlConnection conn)
{
SqlPipe sp = SqlContext.Pipe;
using (conn)
{
// conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
// cmd.Connection = conn;
cmd.CommandText = "Select * from price where name='book1'";
SqlDataReader rdr = cmd.ExecuteReader();
sp.Send(rdr);
}
}这样会不会造成运行一次存储过程就建立一次连接?批量读取数据的时候会很慢吧。
我把conn.open等语句在存储过程中去掉后,运行存储过程会提示
.NET Framework 错误:
System.InvalidOperationException: ExecuteReader: Connection property has not been initialized.就算我在程序里写了连接数据库的代码也一样
SqlConnection sqlcon = new SqlConnection(str); //连接新数据库
sqlcon.Open(); SqlCommand aCommand = new SqlCommand("getdata", sqlcon);
aCommand.CommandType = CommandType.StoredProcedure;
aCommand.ExecuteNonQuery();
该怎样把sqlcon传递给CLR存储过程呢
SqlConnection cn = new SqlConnection("context connection=true");
cn.Open();
这样不是可以连接到数据库了吗?
还是你部署的数据库与连接的数据库为不同的数据库。