2016-05-27 3 views
1

An exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll but was not handled in user codeMySqlを使用しているときにSQL Serverの接続エラーが発生するのはなぜですか?

Additional information: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

web.config

<configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
    </configSections> 
    <connectionStrings> 
    <add name="WebFront" connectionString="Server=localhost;Database=webfront;Uid=devadmin;Pwd=*******" providerName="MySql.Data.MySqlClient" /> 
    </connectionStrings> 

... 

    <system.data> 
    <DbProviderFactories> 
     <remove invariant="MySql.Data.MySqlClient" /> 
     <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> 
    </DbProviderFactories> 
    </system.data> 
    <entityFramework> 
    <providers> 
     <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"> 
     </provider> 
    </providers> 
    </entityFramework> 

すべては私のユニットテストから細かい接続されています。これは、接続文字列内にあるもの以外の認証を提供していない可能性がありますか?サイトに何か他のものがありますか? Owin、Identity、何も使っていない。すべての鐘や笛に追加する前に、基本的なものを学ぼうとしています。

+1

これは、単にマシンがサーバーに接続できないことを意味します。 – Mairaj

+1

ご使用のマシンがDBが存在するサーバーにアクセスできることを確認してください。 – Mairaj

+0

それは同じマシン上にあります... localhostを実行している、ローカルのIIS express、VS2015からすべて。 – IAbstract

答えて

-2

SqlConnectionはSqlServer用です。 MySqlに接続するには、driversをダウンロードしてプロジェクトで参照し、代わりにMySqlConnectionを使用する必要があります。

このquestionとこのCodeProject sampleをご覧ください。

+0

'web.config'を参照してください...すべての参照が行われます。 – IAbstract

0

ユニットテストが動作しているため、メインアプリケーション/サイトでエラーが発生しています。私はVisual StudioとIISサーバーのメインアプリケーションでユニットテストを実行したとします。これが問題の原因ですが正しくない場合、適切な認証方法があり、アプリケーションプールが正しく設定されていることを確認してください。

+0

Visual StudioからIISを実行しているときにIISをどのように構成しますか? – IAbstract

関連する問題