0

ローカルデータベース(mdf)で.netWebサービスを使用しているim。このすべてのWebサイトは、すべてのファイルをそのまま別のコンピューターに移動し、iisで新しいアプリケーションを作成するまで正常に機能していました。このWebサービスのすべてのメソッドは正常に機能し、データベースに接続してクエリを実行する必要があるメソッドだけで、次のエラーが発生します。

System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
   at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
   at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()
   at System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
   at System.Data.Linq.Table`1.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.ElementAt[TSource](IQueryable`1 source, Int32 index)

Web構成接続文字列を数回変更すると、ファイアウォールで保護されません。

ありがとう...

4

3 に答える 3

3

If you are using a MDF file, there must a SQL Server or SQL Server Express installed on your original machine.

As you say that you had moved your files to another computer, your configuration obviously do not work anymore. You will have to adjust all path information to fit to the new installation folders.

Also, you will have to make sure that there is a running SQL Server or SQL Server Express instance on the new computer AND make it point to the MDF database file.

于 2012-11-27T12:29:47.003 に答える
3

MDF は標準の SQL Server 拡張機能であり、SqlClient を使用して接続しているため、間違いなく SQL Server を使用していますが、実際の SQL Server サービスではなく、ローカル データベース (MDF) ファイルに接続しています。

  • Web アプリケーションを実行しているアカウントが MDF ファイルにアクセスできることを確認してください。

  • 接続文字列が connect であることを確認してください。少なくともここに投稿してください。

  • トラブルシューティングを開始するには、一時的に Everyone グループに MDF ファイルへのアクセスを許可し、それが役立つかどうかを確認します。

于 2012-11-27T12:36:17.683 に答える
1

コードだけに集中するよりも、いくつかのインフラストラクチャ チェックをお勧めします。

  1. SQL サーバーに適切な LAN 接続があることを確認します
  2. Web サービスをホストしているサーバーから SQL Server をホストしているサーバーに ping を送信します。
  3. MAnagement Studio を使用して、別のサーバーからデータベース オブジェクトを照会します (ネットワーク管理者が重要なポートを誤ってブロックした可能性があります)。

可能であれば、接続文字列を 2 回チェックしてください。セミコロンがすべてを台無しにすることがあります。

編集

接続文字列

<add name="gatewayConnectionString" 
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=c:\Projects\p\file.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" 
providerName="System.Data.SqlClient"/> 

それが役に立てば幸い、

于 2012-11-27T12:10:35.757 に答える