2012-04-25 6 views
-7

ユーザーが入力する接続文字列がSql Server 2008のものであることをどのように検証しますか?私はC#を使用しています。接続文字列がSql Server 2008のものであることを確認してください

+1

どういう意味ですか? *バージョン*を確認しますか?または製品ですか?接続文字列からバージョンを確認することはできません。同じ文字列が多くのバージョンのSQL Serverで動作します –

+1

http://alexpinsker.blogspot.co.uk/2009/12/regular-expressions-for-connection.html –

+0

それは良い質問です! –

答えて

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は接続文字列が "for" SQL Server 2008であることを検証するように求められているようです。それが有効かどうかだけではありません。 –

+0

SQL Serverのバージョンを取得したい場合は、SQL Serverに接続せずに(私の答えを更新して可能性を示すように)更新しないでください。接続されている場合は、それも妥当性の証明です。 – Sascha

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を忘れてしまった! ;) あ、ちょっと待って... –

関連する問題