CLR存储过程
public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void StoredProcedure1()
{
// 在此处放置代码
SqlConnection sqlConnection = new SqlConnection("context connection=true");
sqlConnection.Open();
SqlCommand sqlCommand = new SqlCommand("select * from ttt", sqlConnection);
SqlDataReader dr=sqlCommand.ExecuteReader();
SqlContext.Pipe.Send(dr);
dr.Close();
sqlConnection.Close();
}
};
调用存储过程
SqlConnection Conn = new SqlConnection("Data Source=xxx.xxx.xxx.xxx;Initial Catalog=testDB;User ID=xxx;Password=xxx");
Conn.Open();
SqlCommand sqlcmd = new SqlCommand("StoredProcedure1", Conn);
sqlcmd.CommandType = CommandType.StoredProcedure;
SqlDataReader dr=sqlcmd.ExecuteReader();
while (dr.Read())
{
Response.Write(dr[1].ToString());
}