本文介绍了错误消息我显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误消息:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
public class commonfunction
{
#region Variable Declaration
SqlConnection _connection;
SqlCommand _command;
SqlDataAdapter _Adapter;
DataSet _DS;
int _count;
#endregion
#region Get DataSet
public DataSet GetDataSet(string _query)
{
try
{
_DS = new DataSet();
_connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString);
_command = new SqlCommand(_query, _connection);
_Adapter = new SqlDataAdapter(_command);
_Adapter.Fill(_DS);
return _DS;
}
catch (Exception)
{
throw;
}
finally
{
_DS.Dispose();
}
}
#endregion
#region Execute Query
public int ExecuteQuery(string _query)
{
try
{
_connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString);
_connection.Open();
_command = new SqlCommand(_query, _connection);
_count = _command.ExecuteNonQuery();
_connection.Close();
return _count;
}
catch (Exception)
{
throw;
}
finally
{
_connection.Close();
}
}
#endregion
}
推荐答案
这篇关于错误消息我显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!