ASP.net 2.0 aspnetdb.mdf deployment based on SQL Server 2005

Source: Internet
Author: User
Tags sql server connection string sql server express connectionstrings
Asp.net|server|sqlserver


Since I only installed SQLSERVER2005 on my machine, instead of installing SQL Server EXPRESS, I deployed the user Profile encountered Aspnetdb.mdf can not connect the problem, after a toss, finally solved, the following experience to write down to share with you.



Because there is no aspnetdb.mdf database, you have to create one, which can be done through Aspnet_regsql.exe, which is located under C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\. 

Press the "Next >" button 

we find that in addition to the configuration database, there is also the ability to delete the database, in the future may be useful, now naturally selected Configure SQL Server for application services, press the "Next >" button

Now go to the database selection interface, and if SQL Server is installed locally, you can simply press "Next >" without changing anything. The database shown here is <default&gt, which means the default is ASPNETDB, and you can change the name to suit your needs.
 now press "Next >" can start to install the database, when the Finish button is lit, indicating the success of the database installation, everything goes well!

The next step is to set the database connection string.
By default, the LocalSqlServer property in Web.config is configured like this:

<connectionStrings>
<add name= "LocalSqlServer" connectionstring= "Data source=./sqlexpress;integrated security=true; attachdbfilename=| Datadirectory|aspnetdb.mdf; User Instance=true "
Providername= "System.Data.SqlClient"/>
</connectionStrings>


This connection string is specially prepared for SQL Server Express, and the following error occurs if SQL Server Express is not installed



An error has occurred while establishing a connection to the server. When connecting to SQL Server in failure, this is caused by the fact that under the default settings SQL server does not allow remote connections. (Provider:sql network interfaces, Error:26-error locating server/instance)



This indicates that the connection could not be established at all. To this end, I tried to change DataSource to./local SQL Server instance name, resulting in an error:
Login Failed for User machinename\aspnet



Again, try to set the user instance to false and error again:



Invalid value for key ' AttachDbFileName '.



In fact, the reason for the error is very simple, because the App_Data directory does not aspnetdb.mdf this file. Checked on the Internet, finally found the solution, reset the connection string to


<add name= "LocalSqlServer" connectionstring= "Data source=[instance name];initial catalog=aspnetdb;integrated Security=false; Uid=sa; Pwd=xxxxxx "



is actually standard SQL Server connection string, depressed ...




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.