我有 2 个课程,第一个Connector课程
public class Connector
{
private SqlConnection sqlCon = new SqlConnection();
public ErrorProvider ConnectTo(string serverID, string databaseName)
{
ErrorProvider errorProv = new ErrorProvider();
const string defineString = "Data Source={0};Initial Catalog={1};Integrated Security=True;Asynchronous Processing=true;MultipleActiveResultSets=True";
try
{
if (sqlCon.State == ConnectionState.Open && sqlCon.ConnectionString == string.Format(defineString, serverID, databaseName))
{
errorProv.ConnectionStatus = ConnectionStat.Success;
}
sqlCon.ConnectionString = string.Format(defineString, serverID, databaseName);
sqlCon.Open();
sqlCon.Close();
errorProv.ConnectionStatus = ConnectionStat.Success;
}
catch (SqlException ex)
{
errorProv.ConnectionStatus = ConnectionStat.Fail;
errorProv.ErrorMessage = ex;
}
return errorProv;
}
}
现在我想将值发送给其他类调用ErrorProvider
public class ErrorProvider
{
public ConnectionStat ConnectionStatus { get; set; }
public SqlException ErrorMessage { get; set; }
public ConnectionDetils ConnectionDet;
}
public enum ConnectionStat
{
Success,
Fail
}
public class ConnectionDetils
{
public string ServerID { get; set; }
public string DatabaseName { get; set; }
public string UserName { get; set; }
}
当我尝试在这段代码中使用它时,它什么也没返回
OT.ConnectTo("(local)", "TestOTLab").ErrorMessage.ToString
OT.ConnectTo("(local)", "TestOTLab").ConnectionStatus.ToString
我希望它按错误值、连接状态、DatabaseName、ServerID 和用户名返回。我怎么能这样做