我收到错误:
System.Data.SqlClient.SqlException(0x80131904):超时已过期。
在我的C#应用程序中。更新数据库中的存储过程后,会出现此问题。
这是我的c#代码。
try
{
string connectionString = ConfigurationManager.ConnectionStrings["dsmmdb"].ToString();
connection = new SqlConnection(connectionString);
//Build query
string sql = string.Format("EXEC [DSMMTracker_ACQ_GetGeoByIp] @IpAddress = N'{0}'", serverVarRemoteAddr);
log.Debug(sql);
connection.Open();
SqlCommand cmd = new SqlCommand(sql, connection);
//Execute DSMMTracker_ACQ_GetGeoByIp stored procedure
var geoReader = cmd.ExecuteReader();
while (geoReader.Read())
{
target.Geo = ACQConfig.PREFIX_TOKEN_GEO_COUNTRY + geoReader["CountryCode"].ToString().ToLower() + "+";
target.Geo += ACQConfig.PREFIX_TOKEN_GEO_CITY + geoReader["CityName"] == null ? "" : ACQConfig.PREFIX_TOKEN_GEO_CITY + geoReader["CityName"].ToString().ToLower() + "+";
target.Geo += ACQConfig.PREFIX_TOKEN_GEO_REGION + geoReader["RegionName"] == null ? "" : ACQConfig.PREFIX_TOKEN_GEO_REGION + geoReader["RegionName"].ToString().ToLower();
log.Debug("Country Code: " + geoReader["CountryCode"].ToString().ToLower());
log.Debug("City Name: " + geoReader["CityName"].ToString().ToLower());
log.Debug("Region Name: " + geoReader["RegionName"].ToString().ToLower());
target.Geo = target.Geo.TrimEnd('+');
}
}
catch (Exception ex)
{
log.Error("Error retrieving geo information from IP address: " + ex.ToString());
}
finally
{
if(connection != null && connection.State == System.Data.ConnectionState.Open)
connection.Close();
}
存储过程在SQL Server Management Studio中正常运行。
运行C#代码时的错误触发器。
感谢。
答案 0 :(得分:0)
使用
string connectionString = ConfigurationManager.ConnectionStrings["dsmmdb"].ConnectionString;
而不是:
string connectionString = ConfigurationManager.ConnectionStrings["dsmmdb"].ToString();