Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Connection problem

derach2000derach2000 Posts: 2Member
Hi,

I'm having some difficulty with connecting an executeing sql statements against the sql server 2000. I'm working in vs2005. I used the folowing code:


SqlConnection myConnection = new SqlConnection("user id=username;" +

"password=pass;server=servname;" +
"Trusted_Connection=yes;" +

"database=databasename; " + "connection timeout=30");
try

{

myConnection.Open();

}

catch (Exception ef)
{

Console.WriteLine(ef.ToString());
}

SqlCommand myCommand1 = new SqlCommand("delete tabele1", myConnection);
SqlCommand myCommand = new SqlCommand("INSERT INTO tabele1(column1, column2) " +

"select month(s.column3),sum(s.column4) from tabele2 s group by month(s.column3) order by month(s.column3)", myConnection);myCommand1.ExecuteNonQuery();
myCommand.ExecuteNonQuery();

try
{
myConnection.Close();

}

catch (Exception er)
{Console.WriteLine(er.ToString());
}

Problem is that that I get an error timeout expired or server not responding on the line myCommand.ExecuteNonQuery();

When I compile the application 3 times then it works. First two times it throwse the exception, and after that it works fine. If I start the servers query analyzer of profiler withe the same name and password the program works fine from the first time. There is obviously some connection problem, but what....


Sign In or Register to comment.