Determine version of SQL Server from ADO.NET

后端 未结 5 1340
难免孤独
难免孤独 2021-01-01 19:42

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

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-01 20:01

    SqlConnection con = new SqlConnection("Server=localhost;Database=test;user=admin;password=123456;");
    con.Open();
    Text = con.ServerVersion;
    con.Close();
    

    con.ServerVersion will give you:

    • 9.x.x for SQL Server 2005
    • 10.x.x for SQL Server 2008

提交回复
热议问题