📄 frmconnection.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
namespace SMODemos
{
public partial class frmConnection : Form
{
public frmConnection()
{
InitializeComponent();
}
private void chkSSPI_CheckedChanged(object sender, EventArgs e)
{
bool blnEnableControls = true;
if (chkSSPI.Checked == true)
{
blnEnableControls = false;
}
lblPWD.Enabled = blnEnableControls;
lblUID.Enabled = blnEnableControls;
txtPwd.Enabled = blnEnableControls;
txtUID.Enabled = blnEnableControls;
}
private void btnConnect_Click(object sender, EventArgs e)
{
//ServerConnection object used to connect
ServerConnection conn = new ServerConnection();
//pass in the name of the server/instance
conn.ServerInstance = txtServer.Text.ToString();
//determine if integrated security is set
if (chkSSPI.Checked == false)
{
//using sql security
conn.LoginSecure = false;
conn.Login = txtUID.Text.ToString();
conn.Password = txtPwd.Text.ToString();
}
//try to connect and return server information
try
{
Server svrLocal = new Server(conn);
//pop up the message box to the user here
//get the info via the Information property
MessageBox.Show("You are not connected to: " + svrLocal.Name + System.Environment.NewLine +
" Edition Info: " + svrLocal.Information.Edition + System.Environment.NewLine +
" Version Info: " + svrLocal.Information.Version,"SMO Demos");
}
catch (SmoException exSMO)
{
//catch SMO specific exceptions
MessageBox.Show(exSMO.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -