Unable to connect to SQL Server database

I am creating a web application in mvc 4.0 and I need to enable membership and authorization using the Asp.netWeb site administration tool, but when I click on the security tab, it leads to an error

There is a problem with the selected data store. This may be due to an invalid server name or credentials or insufficient permission. It can also be called by the role manager function, and not enabled. Click the button below to redirect to a page where you can select a new data warehouse. The following message may help diagnose the problem: Cannot connect to the SQL Server database.

and my connection string is below

<connectionStrings> <add name="MusicStoreEntities" connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf" providerName="System.Data.SqlClient"/> </connectionStrings> 

I can not find the error in the code, so please help me

+7
source share
2 answers

Install them in your web.config

 <membership defaultProvider="SqlMembershipProvider"> <providers> <add name="SqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="MusicStoreEntities" /> </providers> </membership> 

Roles

 <roleManager defaultProvider ="SqlRoleProvider" > <providers> <add name="SqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="MusicStoreEntities" /> </providers> </roleManager> 

see http://msdn.microsoft.com/en-us/library/ms731049.aspx for more information

ps canceled the example here

+9
source

I don’t know that the error was caused by incorrect credentials or what, but I can tell you another method with which you can also check the connection to the database. Do this way

  • Go to Visual Studio, Visual Studio Tools, and then open the Visual Studio Command Prompt.
  • Now write the aspnet_regsql.exe command to launch the ASP.NET SQL Server Setup Wizard. Click further on this screen to go to another screen.
  • click "Next" again, without changing any option from the switches, so here he will ask you about the Information database.
  • Test your connection, and after you are done, you see the ASp.net membership tables are automatically created in the database that you selected.

This error can also be caused due to lack of permissions or the database you are using, there may already be membership tables, you can check this in your database. If the above suggestion does not work for you, try this or your method using the new database.

0
source

All Articles