PDA

View Full Version : مشکل با ConnectionString



ahmad156
شنبه 10 تیر 1391, 19:29 عصر
سلام دوستان.

private SqlDataAdapter da;
private SqlConnection connection;
public DBInterface()
{
connection = new SqlConnection(@"Server=AHMAD-PC\MSSQLSERVER2008;initial catalog=eco;integrated security=true");
da = new SqlDataAdapter();
}

private SqlConnection openConnection()
{
if (connection.State == ConnectionState.Closed || connection.State == ConnectionState.Broken)
{
connection.Open();
}
return connection;
}



public int ExecuteNoneQuery(string query)
{
using (SqlConnection conn = openConnection())
{
SqlCommand command = new SqlCommand();
command.CommandText = query;
command.CommandType = CommandType.Text;
command.Connection = conn;
try
{
return command.ExecuteNonQuery();
}
catch (Exception e)
{
return -1;
}
finally
{
conn.Close();
}
}
}

وقتی من یه بار از تابع ExecuteNoneQuery استفاده میکنم دفعه بعد خطای
The ConnectionString property has not been initialized


میده.چرا؟؟؟؟؟