-7

ユーザーが入力した接続文字列がSQLServer2008用であることをどのように検証しますか?私はC#を使用しています。

4

3 に答える 3

2

私はあなたが何を求めているのか完全にはわかりません。接続文字列がSQLServer2008用であるかどうかをどのように判断するか(コードではなく)簡単な言葉で教えてください。接続文字列は、サーバー名(および適切な場合はインスタンス)、データベース名、資格情報などを指定します。接続文字列には、バージョンを指定するものはありません。

サーバーがSQLServer2008を実行しているかどうかを確認する必要がありますか?接続に成功したら、次を発行してこれを行うことができます。

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 に答える
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 に答える