我得到一个错误:
System.Data.SqlClient。SqlException (0x80131904): Timeout expired.
在我的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#代码时,错误触发。
谢谢。
使用
string connectionString = ConfigurationManager.ConnectionStrings["dsmmdb"].ConnectionString;
代替:
string connectionString = ConfigurationManager.ConnectionStrings["dsmmdb"].ToString();