VSTS 2005 写SQL Server存储过程基础 (C#)
VSTS 2005 写SQL Server存储过程(Procedue)
1、新建一个Sql Server Project
2、写存储过程,C#示意代码如下:
1
[SqlProcedure]
2
public static void BackupDatabase(string strDatabaseName, string strFilePath)
3
{
4
using(SqlConnection conn = new SqlConnection("context connection=true"))
5
{
6
try
7
{
8
// Procedure here. e.g.
9
// string strSQLCmd = "your command here";
10
// conn.Open();
11
// SqlCommand cmd = new SqlCommand(strSQLCmd, conn);
12
// cmd.ExecuteNonQuery();
13
}
14
catch (Exception ex)
15
{
16
// Exception here
17
}
18
finally
19
{
20
conn.Close();
21
}
22
}
23
}
[SqlProcedure]2
public static void BackupDatabase(string strDatabaseName, string strFilePath)3
{4
using(SqlConnection conn = new SqlConnection("context connection=true"))5
{6
try7
{8
// Procedure here. e.g.9
// string strSQLCmd = "your command here";10
// conn.Open();11
// SqlCommand cmd = new SqlCommand(strSQLCmd, conn);12
// cmd.ExecuteNonQuery();13
}14
catch (Exception ex)15
{16
// Exception here17
}18
finally19
{20
conn.Close();21
}22
}23
}3、配置该Project的DataBase连接属性
4、部署(Deploy):项目点右键,选择Deploy
5、到SqlServer中看看把,已经有你的Procedue了。


浙公网安备 33010602011771号