public static string GetStrConn( bool vBolNeedCheckdata)
{
string functionReturnValue = null;
WinConfig DBSet = new WinConfig();
string StrConn = null;
SqlClient.SqlConnection Conn = new SqlClient.SqlConnection();
SqlClient.SqlCommand myCMD = default(SqlClient.SqlCommand);
string StrSQL = null;
SqlClient.SqlDataReader myReader = default(SqlClient.SqlDataReader);
DBSet.XmlFileName = Microsoft.VisualBasic.Compatibility.VB6.GetPath + "\\" + "WinConfig.xml";
DBSet.WindowName = "Data";
StrConn = "data source=" + DBSet.ReadData("ServerName") + ";initial catalog=" + DBSet.ReadData("DateBase") + ";password=" + DBSet.ReadData("PassWord") + ";persist security info=True;user id=" + DBSet.ReadData("User") + ";workstation id=PERMANI;packet size=4096;";
DBSet = null;
if (vBolNeedCheckdata == true) {
Conn.ConnectionString = StrConn;
//If Conn.State = ConnectionState.Closed Then Conn.Open()
StrSQL = "select top 1 T_FileName from TM_FileVer";
myCMD = new SqlClient.SqlCommand(StrSQL, Conn);
if (myCMD.Connection.State == ConnectionState.Closed) {
myCMD.Connection.Open();
}
myReader = myCMD.ExecuteReader;
myReader.Read();
if (myCMD.Connection.State == ConnectionState.Open) myCMD.Connection.Close();
}
functionReturnValue = StrConn;
PROC_EXIT:
if ((myReader != null)) {
if (myReader.IsClosed == false) myReader.Close();
myReader = null;
}
if ((myCMD != null)) {
if (myCMD.Connection.State == ConnectionState.Open) myCMD.Connection.Close();
myCMD.Dispose();
}
if ((Conn != null)) {
Conn.Dispose();
}
return;
PROC_ERROR:
functionReturnValue = "";
Interaction.MsgBox("数据库链接错误,请检查网络是否畅通,服务是否开启!", 48, "系统提示");
goto PROC_EXIT;
return functionReturnValue;
}
{
string functionReturnValue = null;
WinConfig DBSet = new WinConfig();
string StrConn = null;
SqlClient.SqlConnection Conn = new SqlClient.SqlConnection();
SqlClient.SqlCommand myCMD = default(SqlClient.SqlCommand);
string StrSQL = null;
SqlClient.SqlDataReader myReader = default(SqlClient.SqlDataReader);
DBSet.XmlFileName = Microsoft.VisualBasic.Compatibility.VB6.GetPath + "\\" + "WinConfig.xml";
DBSet.WindowName = "Data";
StrConn = "data source=" + DBSet.ReadData("ServerName") + ";initial catalog=" + DBSet.ReadData("DateBase") + ";password=" + DBSet.ReadData("PassWord") + ";persist security info=True;user id=" + DBSet.ReadData("User") + ";workstation id=PERMANI;packet size=4096;";
DBSet = null;
if (vBolNeedCheckdata == true) {
Conn.ConnectionString = StrConn;
//If Conn.State = ConnectionState.Closed Then Conn.Open()
StrSQL = "select top 1 T_FileName from TM_FileVer";
myCMD = new SqlClient.SqlCommand(StrSQL, Conn);
if (myCMD.Connection.State == ConnectionState.Closed) {
myCMD.Connection.Open();
}
myReader = myCMD.ExecuteReader;
myReader.Read();
if (myCMD.Connection.State == ConnectionState.Open) myCMD.Connection.Close();
}
functionReturnValue = StrConn;
PROC_EXIT:
if ((myReader != null)) {
if (myReader.IsClosed == false) myReader.Close();
myReader = null;
}
if ((myCMD != null)) {
if (myCMD.Connection.State == ConnectionState.Open) myCMD.Connection.Close();
myCMD.Dispose();
}
if ((Conn != null)) {
Conn.Dispose();
}
return;
PROC_ERROR:
functionReturnValue = "";
Interaction.MsgBox("数据库链接错误,请检查网络是否畅通,服务是否开启!", 48, "系统提示");
goto PROC_EXIT;
return functionReturnValue;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货