SQL Server2008 管理对象 (SMO)
转自http://technet.microsoft.com/zh-cn/library/ms162132.aspx
SQL Server 身份验证连接到 SQL Server 的实例
public static void Main() {
String sqlServerLogin = "user_id";
String password = "pwd";
String instanceName = "instance_name";
String remoteSvrName = "remote_server_name";
// Connecting to an instance of SQL Server using SQL Server Authentication
Server srv1 = new Server(); // connects to default instance
srv1.ConnectionContext.LoginSecure = false; // set to true for Windows Authentication
srv1.ConnectionContext.Login = sqlServerLogin;
srv1.ConnectionContext.Password = password;
Console.WriteLine(srv1.Information.Version); // connection is established
// Connecting to a named instance of SQL Server with SQL Server Authentication using ServerConnection
ServerConnection srvConn = new ServerConnection();
srvConn.ServerInstance = @".\" + instanceName; // connects to named instance
srvConn.LoginSecure = false; // set to true for Windows Authentication
srvConn.Login = sqlServerLogin;
srvConn.Password = password;
Server srv2 = new Server(srvConn);
Console.WriteLine(srv2.Information.Version); // connection is established
// For remote connection, remote server name / ServerInstance needs to be specified
ServerConnection srvConn2 = new ServerConnection(remoteSvrName);
srvConn2.LoginSecure = false;
srvConn2.Login = sqlServerLogin;
srvConn2.Password = password;
Server srv3 = new Server(srvConn2);
Console.WriteLine(srv3.Information.Version); // connection is establishedSQL Server 管理对象 (SMO)
我的记事本
浙公网安备 33010602011771号