經過一段時間使用網站,加載內容等。此消息顯示「填充:SelectCommand.Connection屬性尚未初始化」! 我認爲這是因爲sql連接,但不知道...我想知道我能做些什麼來防止這種情況發生,每次發生這種情況時,我都必須上傳一個文件(SQL類,用於連接)和該網站開始再次運作。填充:SelectCommand.Connection屬性尚未初始化
我的SQL連接:
public class SQL
{
SqlCommand comandos;
public SqlConnection sql()
{
string Server = @"server";
string Username = "user";
string Password = "pass";
string Database = "database";
string ConnectionString = "Data Source=" + Server + ";";
ConnectionString += "User ID=" + Username + ";";
ConnectionString += "Password=" + Password + ";";
ConnectionString += "Initial Catalog=" + Database;
SqlConnection Connection = new SqlConnection();
try
{
Connection.ConnectionString = ConnectionString;
Connection.Open();
return Connection;
}
catch (Exception)
{
if (Connection != null)
{
Connection.Dispose();
}
return null;
}
}
public void FazerComando(string comando)
{
comandos = new SqlCommand(comando, sql());
comandos.ExecuteNonQuery();
}
public DataTable Execute(string comando)
{
SqlDataAdapter SQLDataAdapter = new SqlDataAdapter(comando, sql());
DataTable dtResult = new DataTable();
SQLDataAdapter.Fill(dtResult);
return dtResult;
}
}
我認爲它的工作,我推動網站,它沒有崩潰!坦克很多! – Severiano