C#, SQL Server. Provider: TCP Provider, error: 0 - No such host is known

  • Thread starter Thread starter NiceStepUp
  • Start date Start date
N

NiceStepUp

Guest
My connection string looks like this:

Data Source=sql88;Initial Catalog=Osm;User ID=foouser;Password=foopsw

The code that creates connection string looks like this:

var con = new SqlConnectionStringBuilder();
if (string.IsNullOrEmpty(model.Username) && string.IsNullOrEmpty(model.Password))
con.
IntegratedSecurity = true;
else
{
con.
UserID = model.Username;
con.
Password = model.Password;
}
con.
DataSource = model.Host ?? string.Empty;
con.
InitialCatalog = model.Database ?? string.Empty;
return con;


My application creates database structure at SQL Server, then inserting data. So sometimes the applcation works approximately 14 hours. The code that executes SQL at SQL Server looks like this:

using (var cmd = con.CreateCommand())
{
cmd.
CommandTimeout = int.MaxValue;
cmd.
CommandText = sql;
try
{
cmd.
ExecuteNonQuery();
}
catch (Exception ex)
{
var test = ex.Message;
throw;
}
}


Sometimes application works well, but sometimes application throws an error:


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: TCP Provider, error: 0 - No such host is known.) (Microsoft SQL Server, Error: 11001)

I've read this page, however, in my view this is not my case because sometimes my application works well.

Continue reading...
 
Back
Top