This C# program demonstrates how to select the SQL server version for Microsoft SQL in C#.
using System;
using System.Data.SqlClient;
namespace SelectVersion {
class Program {
static void Main(string[] args) {
Console.WriteLine(SelectVersion());
}
public static string SelectVersion() {
// The using block ensures that the connection is closed when it exits this block.
using (SqlConnection qConnection = new SqlConnection(
@"Server=localhost\SQLEXPRESS01;Trusted_Connection=True;")) {
SqlCommand qCommand = qConnection.CreateCommand();
qCommand.CommandText = "SELECT @@version";
qCommand.Connection.Open();
return qCommand.ExecuteScalar().ToString();
}
}
}
}
Microsoft SQL Server 2017 (RTM-GDR) (KB4494351) - 14.0.2014.14 (X64) Apr 5 2019 09:18:51 Copyright (C) 2017 Microsoft Corporation Express Edition (64-bit) on Windows 10 Home 10.0 <X64> (Build 17763: ) Press any key to continue . . .
© 20072024 XoaX.net LLC. All rights reserved.