0

I have an ASP.NET web site that uses MVC. This works great connecting to a SqlServer DB. I recently modified the code to connect to a MYSql DB and that works. But when accessing some pages I get the following error, which says it is looking for a SQL Server connection.

This is the error:

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)

Has anyone seen this before? I have been dealing with this for a couple of days and have not found any relevant information on this topic. The rest of the error seems to indicate that it is looking for a SqlServer or a Sql Server Express connection. What is confusing is that everything has been changed to use MySql. It seems like it is one of the libraries that is still trying to access a Sql Server DB with the MySql connection string.

Thanks for any help you can provide.

-- update. the problem is that when iis goes into a sub directory in the web site with a web config that includes directory permissions as listed above in the code snipit. It wants to open up a connection to SQL Server or SQL Server Express to do the permission checks. Since I am using MySql for the connection string it gets confused and cannot handle it. It appears the solution would be to alter the machine config. but that would cause problems since I am connecting to SQL Server DB's on other instances in iis. the solution I applied is to remove the sub folder web.config files and make sure that page commissioning is applied on each page directly, which is what I do anyway. The Directory Permission check is just another level of security. But in typical MS fashion they come up short if not using their products.

so the ultimate solution is to not use MS identity mgt unless you write your own. This would also alleviate the obvious upgrade to identity mgt that MS seems to want to do with each new release.

cheers and thanks for all the help. I hope I helped someone else with this issue.

Rsiena
  • 1
  • 1
  • 1
    Can you post the code that causes this exception? – chakeda Nov 28 '18 at 23:19
  • So it seems that the issue is: – Rsiena Nov 29 '18 at 20:06
  • It seems you are using Web.configs in sub directories to do role-based authentication. Now that you've upgraded to MVC, delete those files and try using DataAnnotations instead. Let me know if that helps you: https://learn.microsoft.com/en-us/aspnet/core/security/authorization/roles?view=aspnetcore-2.1 – chakeda Nov 29 '18 at 20:29
  • Asp.net, MVC etc have really nothing to do with this problem. If you have a flat tire, the fact that the car is a V8 or Electric has no bearing. – Erik Philips Nov 29 '18 at 21:38
  • Possible duplicate of [Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?](https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci) – Erik Philips Nov 29 '18 at 21:39

2 Answers2

0

At first you need to download theMySQLConnector. Then you can use the Entity Framework or the SqlCommand to connect to your database.

More Information MySQL Connector for .NET MySQL Entity Framework Tutorial

Ali Dalir
  • 11
  • 4
  • Thanks I have had my code working with mySQL and it started giving the problem above after integrating the code with MVC – Rsiena Nov 30 '18 at 14:49
-1

This will be helpful C# application with MYSQL database example

  • [When someone goes on Stack Exchange, the question "answer" should actually contain an answer. Not just a bunch of directions towards the answer.](https://meta.stackexchange.com/a/8259/171858). – Erik Philips Nov 29 '18 at 21:41
  • I am new to stack overflow and trying to be helpful. I apologise for the same and will take care for the same in future. – Chintan Bataviya Nov 30 '18 at 06:09
  • Thanks, First time I an seeking outside help. I usually do extensive searches on the problem first. but this one seemed to allude me. – Rsiena Nov 30 '18 at 14:52