C#winform 怎么改造下列代码,
改造下列代码,将它改造成
通过这个代码来连接数据库,其他不变, server=176.16.0.33;uid=sa;password=sa;database=PDMIS
以下是源代码
//连接服务器,并获取连接字符串
private bool ConnectServer()
{
try
{
Desay.HR.Business.ConnectionString cs = new ConnectionString(txtServer.Text, Convert.ToInt32(numPort.Value));
connectionString = cs.GetConnectionStringByKey("PDMIS");
return true;
}
catch (Exception ex)
{
MessageBox.Show("服务器连接失败!\n失败描述:" + ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
//TcpChannel channel = new TcpChannel();
//ChannelServices.RegisterChannel(channel, false);
//string uri = string.Format("tcp://{0}:{1}/DataService", txtServer.Text, numPort.Value);
//try
//{
// IDataService ds = (IDataService)Activator.GetObject(typeof(DataService), uri);
// connectionString = ds.GetDataServer();
// return true;
//}
//catch (Exception ex)
//{
// MessageBox.Show("服务器连接失败!\n失败描述:" + ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// return false;
//}
//finally
//{
// ChannelServices.UnregisterChannel(channel);
//}