疯了,帮忙看啊这个数据库连接error
有两个函数,都是连同一个数据库,第一个是用Linq查询,第二个函数是传统stored procedure.
public static CreditCardBizSetupLQEntity GetCreditCardBizSetupByBizID(int bizID)
{
DbHelper dbHelper = new DbHelper(Constants.DEFAULT_CONNECTIONSTRING);
DataContext db = new DataContext(dbHelper.GetConnection());
var list =
(from b in db.GetTable<CreditCardBizSetupLQEntity>()
where b.BizID == bizID
select b).ToList();
if (list.Count != 1)
{
return null;
}
CreditCardBizSetupLQEntity ccBizSetup = list[0];
return ccBizSetup;
}
这第一个函数的数据库连接在每晚2点-6点之间总报一下错误(白天运转正常,只有2点-6点之间报错)
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
然后在第一个函数报错的同时,我会调用第二个函数写log进入数据库(和第一个函数连接的是同一个数据库)
public static int InsertLog(String cardNumber, String request, String step, int success, String msg, String exception)
{
DbHelper db = null;
try
{
db = new DbHelper(Constants.DEFAULT_CONNECTIONSTRING);
db.AddParameter("@CardNumber", cardNumber);
db.AddParameter("@Request", request);
db.AddParameter("@Step", step);
db.AddParameter("@Success", success);
db.AddParameter("@Msg", msg);
db.AddParameter("@Exception", exception);
return db.ExecuteNonQuery("TPC_CreditCard_InsertLog", CommandType.StoredProcedure);
}
catch (Exception ex)
{
msg = SYSTEM_ERROR_WORDING + ex.Message;
return -1;
}
finally
{
// over kill
if (db != null)
{
db.CloseConnection();
}
}
}
奇怪的地方就是,连接的同一个数据库,同一个时间,
都是用db = new DbHelper(Constants.DEFAULT_CONNECTIONSTRING)连接数据库
第一个函数报错,第二个函数却能正常操作
这是为什么?啊啊 啊 啊