Ensure you can sign into SQL Server Management Studio.
Follow these steps if the following error appears when attempting to create a login system in Visual Studio: 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)
Note: This should only appear if using Window 7 or Windows Server 2008 R2 and using SQL Server Express. This workaround should not be used in a production environement, because giving the Network Service read and write access creates a vulnerability.
According to the book Beginning ASP.NET 4 by Imar Spaanjaars, the Login control talks to the ASP.NET application service providers, which is a software layer that sits between the login control and the SQL Server database. The very first time you try to log in, the application service providers check to see if your application is using a database with the necessary database objects, such as the appropriate tables and roles. If not, the application service providers should automatically create the ASPNETDB.MDF. Ensure Visual Studio is pointing to the correct instance of SQL Server.
Follow the instructions in the article on How to get started with Microsoft SQL Server (MSSQL) in Visual Studio to ensure the Test Connection is successful when using SQL Server Authentication. Once there is a successful Test Connection, there should be a connectionString in the Web.config file.
<configuration> <connectionString> <add name="databasenameConnectionString" connectionString="Data Source=server1\database1; Initial Catalog=databasename; Persist Security Info=True; User ID=username1; Password=SuperSecretPassword" providerName="System.Data.SqlClient" />
Add the following markup to the web.config file in Visual Studio. Notice the name of the connectionString in this example is databasenameConnectionString. Use the same in the following markup.
<system.web> <authentication mode="Forms" > </authentication> <authorization> <deny users="?" /> </authorization> <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15"> <providers> <clear /> <add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="databasenameConnectionString" applicationName="MyApplication" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed" /> </providers> </membership> </system.web>
In a command line prompt, type net stop iisadmin /y or iisreset /stop
Follow these steps to give the network service read access to Visual Studio.
Note: If NETWORK SERVICE is not listed, select Add. In the Select Users or Groups dialog box, type NETWORK SERVICE, select Check Names, and select OK.
Follow these steps to give the network service read and write access your Visual Studio project.
Follow these steps to give the network service read and write access your App_Data folder.
In a command line prompt, type net start iisadmin /y or iisreset /start
More information here: https://support.microsoft.com/en-us/kb/2002980