0

I've having some trouble in connecting mvc 3 application in .net. I know that mysql database instance has to be created before using web.config file to connect the it. My connectionStrings as below:

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

and I've got a database name call epmsDb created in Server explorer. Then I tried to get the connectionString in the code using this :

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

Every time I tried to access the database, I threw this exception:

   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)

I've been trying to overcome this for a week now. Does anyone have ideas why this occurres?

3
  • Did you verify that the named pipes protocol is enabled? Commented Oct 13, 2012 at 12:09
  • I checked and found that the named pipes is off. Do we need to open it? Do you know how to? As far as I know mysql connection using TCP port. Commented Oct 13, 2012 at 22:16
  • Please ignore my comment. When I saw you using SqlClient, I mistakenly assumed you were trying to connect to SqlServer. Very sorry for the confusion. Commented Oct 14, 2012 at 15:20

1 Answer 1

1

Your example tries to connect to an MS SQL database. To connect to a MySQL DB you might want to use the MySQL connector

Then change the ProviderName property:

<connectionStrings>
<add name="epmsDb" 
  connectionString="Server=localhost;Database=database1;
                     Uid=root;Pwd=mypassword"
  providerName="MySql.Data.MySqlClient" />
</connectionStrings>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the solution it is now able to find the database through Server Explorer but I still couldn't connect it through asp.net code. Do you have any other ideas how should I investigate this? Thanks
Make sure the MySql port isn't blocked by the Windows firewall. I believe the default for most versions of MySql is 3306.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.