adam gills

adam gills

  • NA
  • 65
  • 14.3k

A network-related or instance-specific error occurred

Dec 21 2016 8:12 AM
Sir,
 
Sqlconnection string is not again establish when I execute 'update' command after 8 to 10 minuts it's is mandatory.
 
 
 
and shown an error as :-
 

"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 - The requested address is not valid in its context.)  "
 
 
 
 
 
Code is given below
 
if (link == "Delete")
{
DateTime dat = DateTime.Now;
string tdate = dat.ToString("yyyy-MM-dd");
string ttime = dat.ToString("hh:mm:ss");
string procs = "Update ipinfo set deldata='1',username='" + setuser.Trim() + "', deletedate='" + tdate + "',deletetime='" + ttime + "',timediff=convert(varchar(5),DateDiff(s, worktime, '" + ttime + "')/3600)+':'+convert(varchar(5),DateDiff(s,worktime, '" + ttime + "')%3600/60)+':'+convert(varchar(5),(DateDiff(s,worktime, '" + ttime + "')%60))"
+ " where dataid='" + dgvuserinfo.Rows[e.RowIndex].Cells["ID"].Value + "' ";
cmd = new SqlCommand(procs, mycon);
mycon.Open();
cmd.ExecuteNonQuery();
mycon.Close();
refreshgrid();

Answers (2)