2012-04-25 52 views
-7

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

+1

你是什么意思?你想验证*版本*?或者产品?您无法从连接字符串验证版本 - 相同的字符串将适用于许多版本的SQL Server – 2012-04-25 17:12:12

+1

http://alexpinsker.blogspot.co.uk/2009/12/regular-expressions-for-connection.html – 2012-04-25 17:13:52

+0

这是个好问题! – 2013-12-16 15:10:46

回答

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
  1. 尝试连接到SQL服务器。出错时,它是无效的
  2. 使用连接字符串生成器(http://msdn.microsoft.com/de-de/library/ms254947.aspx),只需询问用户所需的值。也许对于你的用户
  3. 容易一点

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

+0

OP似乎要求验证连接字符串是“用于”SQL Server 2008;不仅仅是否有效。 – 2012-04-25 17:13:44

+0

如果他想要得到SQL Server版本,没有办法没有连接到SQL服务器(更新我的答案,以显示它将是可能的)。如果连接,它也是一个有效性的证明。 – Sascha 2012-04-25 17:17:46

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 

如果您有早期版本,好运与那些。 :-)

+0

你忘了SQL Server 6.5! ;) 等一下... – 2012-04-25 17:17:17

相关问题