0

.netでmvc3アプリケーションを接続する際に問題が発生しました。web.configファイルを使用して接続する前に、mysqlデータベースインスタンスを作成する必要があることを知っています。私のconnectionStringsは次のとおりです。

<connectionStrings>
<add name="epmsDb" 
  connectionString="Server=localhost;Database=database1;
                     Uid=root;Pwd=mypassword"
  providerName="System.Data.SqlClient" />
</connectionStrings>

サーバーエクスプローラーでepmsDbというデータベース名を作成しました。次に、これを使用してコードでconnectionStringを取得しようとしました:

  string connectionString =
          ConfigurationManager.ConnectionStrings["epmsDb"].ConnectionString;
        context = new DataContext(connectionString);
        usersTable = context.GetTable<UserObj>();

データベースにアクセスしようとするたびに、次の例外をスローしました。

   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)

私はこれを1週間克服しようとしています。なぜこれが起こるのか誰かが考えを持っていますか?

4

1 に答える 1

1

あなたの例は、MSSQLデータベースに接続しようとしています。MySQL DBに接続するには、MySQLコネクタを使用することをお勧めします

次に、ProviderNameプロパティを変更します。

<connectionStrings>
<add name="epmsDb" 
  connectionString="Server=localhost;Database=database1;
                     Uid=root;Pwd=mypassword"
  providerName="MySql.Data.MySqlClient" />
</connectionStrings>
于 2012-10-13T12:28:00.953 に答える