如何验证用户输入的连接字符串是否适用于Sql Server 2008?我正在使用C#。验证连接字符串是否适用于Sql Server 2008
回答
我不知道为什么你需要验证或用户正在输入连接字符串,但你可以从下面的链接找到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
- 尝试连接到SQL服务器。出错时,它是无效的
- 使用连接字符串生成器(http://msdn.microsoft.com/de-de/library/ms254947.aspx),只需询问用户所需的值。也许对于你的用户 容易一点
编辑:如果你想要得到的SQL Server的版本,你可以得到它,你可以使用select @@version
一旦你连接。请参阅http://msdn.microsoft.com/de-de/library/ms254947.aspx以供参考。但你首先需要连接。
OP似乎要求验证连接字符串是“用于”SQL Server 2008;不仅仅是否有效。 – 2012-04-25 17:13:44
如果他想要得到SQL Server版本,没有办法没有连接到SQL服务器(更新我的答案,以显示它将是可能的)。如果连接,它也是一个有效性的证明。 – Sascha 2012-04-25 17:17:46
我不完全知道你是问什么。你能用简单的语言(而不是代码)告诉我们你将如何确定连接字符串是否适用于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
如果您有早期版本,好运与那些。 :-)
你忘了SQL Server 6.5! ;) 等一下... – 2012-04-25 17:17:17
- 1. 用于远程连接到SQL Server 2008的连接字符串
- 2. SQL Server Express 2008连接字符串
- 3. c#2008 SQL Server Express连接字符串
- 4. SQL Server 2008 - 连接字符串
- 5. SQL Server 2005 SQL身份验证连接字符串
- 6. SQL Server连接字符串
- 7. 1and1.com上适用于SQL Server连接字符串的格式
- 8. 验证字符串是逗号分隔列表SQL Server 2008
- 9. SQL Server 2000连接字符串转换为SQL Server 2008
- 10. SQL Server 2008 SSMS连接和http连接字符串?
- 11. SQL Server连接字符串
- 12. SQL Server连接字符串
- 13. SQL Server连接字符串
- 14. C#Windows应用程序:使用Windows身份验证连接到远程SQL Server 2008的连接字符串
- 15. 从SQL Server更改连接字符串的Windows身份验证
- 16. 用于AspNetDb的Sql身份验证连接字符串
- 17. ServerConnection不适用于连接字符串
- 18. SQL Server 2008链接服务器连接字符串设置
- 19. 验证SQL Server连接
- 20. SQL Server 2008 - 连接字符串的字段
- 21. SQL Server 2012连接字符串
- 22. 的SQL Server:用字符串连接
- 23. Mongoose验证适用于字符串,但不适用于字符串数组
- 24. SQL Server连接字符串问题
- 25. 使用连接字符串连接到提供商的SQL Server 2008
- 26. SQL Server连接字符串问题
- 27. 用于连接字符串的SQL用户是什么?
- 28. 验证SQL Server中的BASE64字符串
- 29. 验证TableAdapter连接字符串是否成功打开?
- 30. 经典ASP global.asa SQL Server 2008连接字符串
你是什么意思?你想验证*版本*?或者产品?您无法从连接字符串验证版本 - 相同的字符串将适用于许多版本的SQL Server – 2012-04-25 17:12:12
http://alexpinsker.blogspot.co.uk/2009/12/regular-expressions-for-connection.html – 2012-04-25 17:13:52
这是个好问题! – 2013-12-16 15:10:46