If you have installed the full SQL Server version, the following error occurs when you use the ASP. NET Website Configuration tool:
Failed to establish database connection. If you have not created an SQL Server database, log out of the website management tool, use the aspnet_regsql command line utility to create and configure the database, and then return to the tool to set the provider.
Generally ,. net will ask the program to find the database in the app_data directory of the current website by default, and then open it with SQL Server Express, which is reflected in the default connection string configuration of IIS and machine. config:
Data Source =. \ sqlexpress; Integrated Security = sspi; attachdbfilename = | datadirectory | aspnetdb. MDF; user instance = true
The problem is, of course, you cannot change it directly, because since we use the full database, we must write the user/role/permission information in the current database, it is impossible to create a database separately and store it in app_data,
The solution is also simple. The program searches for the connection string named localsqlserver by default, so we only need. you can overwrite it in the config file. Note that to overwrite it, you must first remove it and then add it. Otherwise, it will report that it has been defined once.
<Connectionstrings> <remove name = "localsqlserver"/> <Add name = "localsqlserver" connectionstring = "Data Source = .; initial catalog = databasename; user id = sa; Password = PWD; trusted_connection = true; "providername =" system. data. sqlclient "/> </connectionstrings>