Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 224083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:17:00+00:00 2026-05-11T19:17:00+00:00

I need to determine the version of SQL Server (2000, 2005 or 2008 in

  • 0

I need to determine the version of SQL Server (2000, 2005 or 2008 in this particular case) that a connection string connects a C# console application (.NET 2.0). Can anyone provide any guidance on this?

Thanks, MagicAndi

Update

I would like to be able to determine the SQL Server version form the ADO.NET connection object if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:17:01+00:00Added an answer on May 11, 2026 at 7:17 pm

    This code will determine the version of SQL Server database being used – 2000, 2005 or 2008:

    try
    {
        SqlConnection sqlConnection = new SqlConnection(connectionString);
        Microsoft.SqlServer.Management.Smo.Server server = new Microsoft.SqlServer.Management.Smo.Server(new Microsoft.SqlServer.Management.Common.ServerConnection(sqlConnection));
    
        switch (server.Information.Version.Major)
        {
          case 8:
            MessageBox.Show("SQL Server 2000");
            break;
          case 9:
            MessageBox.Show("SQL Server 2005");
            break;
          case 10:
            MessageBox.Show("SQL Server 2008");
                    break;
          default:
            MessageBox.Show(string.Format("SQL Server {0}", server.Information.Version.Major.ToString())); 
            break;   
        }
    }
    catch (Microsoft.SqlServer.Management.Common.ConnectionFailureException)
    {
        MessageBox.Show("Unable to connect to server",
            "Invalid Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
    }
    

    The code below will do the same, this time using NinthSense’s answer:

    try
    {       
        SqlConnection sqlConnection = new SqlConnection(connectionString);
        sqlConnection.Open();
    
        string serverVersion = sqlConnection.ServerVersion;
        string[] serverVersionDetails = serverVersion.Split( new string[] {"."}, StringSplitOptions.None);
    
        int versionNumber = int.Parse(serverVersionDetails[0]);
    
        switch (versionNumber)
        {
            case 8:
                MessageBox.Show("SQL Server 2000");
                break;
            case 9:
                MessageBox.Show("SQL Server 2005");
                break;
            case 10:
                MessageBox.Show("SQL Server 2008");
                break;
            default:
                MessageBox.Show(string.Format("SQL Server {0}", versionNumber.ToString()));  
                break;  
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(string.Format("Unable to connect to server due to exception: {1}", ex.Message),
            "Invalid Connection!", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
    }
    finally
    {
        sqlConnection.Close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to determine which version of GTK+ is installed on Ubuntu Man does
I need to determine the highest .NET framework version installed on a desktop machine
I need to determine which pages of a Word document that a keyword occurs
I need to determine if a user-supplied string is a valid file path (i.e.,
I frequently need to compare SQL procedures to determine what has changed in the
I need to determine which version of browser the user is using, however compatibility
I need to determine if a Class object representing an interface extends another interface,
I need to determine the ID of a form field from within an action
I need to determine the current year in Java as an integer. I could
I need to determine state of last build (success/failure) and I do it like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.