SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Learning...
    Join Date
    Jan 2003
    Posts
    778
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL Server 2005 (express edition) ServerVersion error on Connection Open

    Hi,

    This is what I have in my code:

    This is what I have in my code:

    Code:
     
    static void Main(string[] args)
    {
    
    // Create a new SqlConnectionStringBuilder and // initialize it with a few name/value pairs. SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(GetConnectionString()); builder["Trusted_Connection"] = true; Console.WriteLine(builder.ConnectionString); SqlConnection connection = new SqlConnection(builder.ConnectionString); Console.WriteLine("Press Enter to finish."); Console.ReadLine();
    } private static string GetConnectionString() {
    // To avoid storing the connection string in your code, // you can retrieve it from a configuration file. return "Server=.\\SQLEXPRESS;Integrated Security=SSPI;" + "Initial Catalog=CDStore";
    }

    have looked at many posts, but none of them have been helpful. My application and my database are on my local machine. I have tried giving the actual name of the Server, and the complete path of the database, but to no avail.

    Here is the error I am getting.

    connection.ServerVersion threw an exception of type System.InvalidOperationException.

    I would appreciate any help in this regard.

    Thanks
    The beauty of life is not dependent on how happy you are,
    but on how happy others can be because of you...

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,629
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Why are you using a connection string builder? You should just need to supply the connection string . . .

  3. #3
    Learning...
    Join Date
    Jan 2003
    Posts
    778
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is not the builder, I have tried a simple string as well ... the connection still doesn't work.

    Thanks,
    The beauty of life is not dependent on how happy you are,
    but on how happy others can be because of you...

  4. #4
    Learning...
    Join Date
    Jan 2003
    Posts
    778
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the problem had to do with the connection. Actually I was not opening the connection, and you do not get the Version till the connection is open. So now the code is as under ..... and it works .

    staticvoid Main(string[] args)
    {
    SqlConnection conn = newSqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=CDStore;Integrated Security=true");
    conn.Open();

    Console.WriteLine("Press Enter to finish.");
    Console.ReadLine();
    conn.Close();
    }

    Thanks once again.
    The beauty of life is not dependent on how happy you are,
    but on how happy others can be because of you...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •