-7

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

4

3 回答 3

2
  1. 尝试连接到 SQL 服务器。出错时无效
  2. 使用连接字符串生成器 ( http://msdn.microsoft.com/de-de/library/ms254947.aspx ) 并询问用户所需的值。也许对您的用户来说更容易一些

编辑:如果你想获得 SQL Server 的版本,你可以得到它,你可以select @@version在连接后使用。请参阅http://msdn.microsoft.com/de-de/library/ms254947.aspx以供参考。但是您首先需要连接。

于 2012-04-25T17:12:18.060 回答
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
于 2012-04-25T17:12:31.213 回答
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

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

于 2012-04-25T17:16:30.407 回答