几行代码列举数据库中的所有存储过程和存储过程参数
使用Smo管理对象,可以很方便的列举指定数据库中的所有存储过程和其参数
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using Microsoft.SqlServer.Management.Smo;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
Server server = new Server(".");
Database db = server.Databases["YouDBName"];
foreach (StoredProcedure sp in db.StoredProcedures)
{
if (sp.IsSystemObject)
{
continue;
}
Console.WriteLine(sp.Name);
foreach (Parameter parm in sp.Parameters)
{
Console.WriteLine("\t" + parm.Name + "\t\t" + parm.DataType.SqlDataType.ToString());
}
}
Console.Read();
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using Microsoft.SqlServer.Management.Smo;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
Server server = new Server(".");
Database db = server.Databases["YouDBName"];
foreach (StoredProcedure sp in db.StoredProcedures)
{
if (sp.IsSystemObject)
{
continue;
}
Console.WriteLine(sp.Name);
foreach (Parameter parm in sp.Parameters)
{
Console.WriteLine("\t" + parm.Name + "\t\t" + parm.DataType.SqlDataType.ToString());
}
}
Console.Read();
}
}
}
需要引用Microsoft.SqlServer.ConnectionInfo和Microsoft.SqlServer.Smo两个组件。