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

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use htmlspecialchars to encode just the HTML special characters &,… May 12, 2026 at 1:10 am
  • Editorial Team
    Editorial Team added an answer Not much ideas, except looking at the source code of… May 12, 2026 at 1:10 am
  • Editorial Team
    Editorial Team added an answer Try Active Support with Hash#slice and/or Hash#except. The bang methods… May 12, 2026 at 1:10 am

Related Questions

I've got an interesting design question. I'm designing the security side of our project,
I would like to start tagging my deployed binaries with the latest SVN revision
Thanks to a Q&A on stackoverflow. I just found out how to determine the
I'm using TPTP to profile some slow running Java code an I came across

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.