验证连接字符串是否适用于Sql Server 2008

时间:2012-04-25 17:08:22

标签: c# sql-server-2008

如何验证用户输入的连接字符串是否适用于Sql Server 2008?我正在使用C#。

3 个答案:

答案 0 :(得分:2)

  1. 尝试连接到SQL Server。出错,它无效
  2. 使用连接字符串构建器(http://msdn.microsoft.com/de-de/library/ms254947.aspx)并只询问用户所需的值。对您的用户而言可能更容易一些
  3. 编辑:如果您想获得SQL Server的版本,您可以获得它,您可以在连接后使用select @@version。请参阅http://msdn.microsoft.com/de-de/library/ms254947.aspx以供参考。但是你首先需要连接。

答案 1 :(得分:2)

我不知道你为什么需要验证或用户输入连接字符串,但你可以从下面链接找到sql 2008的连接字符串。

http://www.connectionstrings.com/sql-server-2008

Standard Security
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Use serverName\instanceName as Data Source to connect to a specific SQL Server instance.
Are you using SQL Server 2008 Express? Don't miss the server name syntax Servername\SQLEXPRESS where you substitute Servername with the name of the computer where the SQL Server Express installation resides.

COPY

Standard Security alternative syntax
This connection string produce the same result as the previous one. The reason to include it is to point out that some connection string keywords have many equivalents.
Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;

COPY

Trusted Connection
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

COPY

Trusted Connection alternative syntax
This connection string produce the same result as the previous one. The reason to include it is to point out that some connection string keywords have many equivalents.
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

COPY

Connecting to an SQL Server instance
The syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.
Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=True;

COPY

Trusted Connection from a CE device
Often a Windows CE device is not authenticated and logged in to a domain. To use SSPI or trusted connection / authentication from a CE device, use this connection string.
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword;
Note that this will only work on a CE device.
Read more about connecting to SQL Server from CE devices here

答案 2 :(得分:2)

我不完全确定你在问什么。您能用简单的单词(而不是代码)告诉我们如何确定连接字符串是否适用于SQL Server 2008?连接字符串指定服务器名称(以及适当的实例),数据库名称,凭据等。连接字符串中没有任何内容指定它的用途。

您是否想要验证服务器是否正在运行SQL Server 2008?成功连接后,您可以通过发出以下命令来执行此操作:

SELECT SERVERPROPERTY('ProductVersion');

回答:

  8.0.xxxx.xx = SQL Server 2000
  9.0.xxxx.xx = SQL Server 2005
 10.0.xxxx.xx = SQL Server 2008
10.50.xxxx.xx = SQL Server 2008 R2
 11.0.xxxx.xx = SQL Server 2012

如果你有早期版本,祝你好运。 : - )

相关问题