WebPart database connection problems

Source: Internet
Author: User
Tags sql server express
I recently started to learn. NET 2.0, and I was troubled by the problem ....

I like the WebPart function in. NET 2.0 very much. However, I just put a WebPartManager on the page as instructed in the tutorial, and then run it, and an error is returned:

The server error in the "/WebSite1" application.

An error occurred while establishing a connection with the server. When you connect to SQL Server 2005, the default setting does not allow remote connection to SQL Server may cause this failure. (Provider: SQL network interface, error: 26-An error occurred while locating the specified server/instance)

Note:An error occurred while executing the current Web request. Check the stack trace information for details about the error and the source of the error in the code.

An error occurred while creating the SQLExpress database file:

The connection string specifies a local SQL Server Express instance using the database location in the App_Data directory of the application. Because the provider determines that the Application Service database does not exist, it attempts to automatically create the database. To successfully check whether the application service database exists and automatically create an Application Service database, the following configuration requirements must be met:

  1. If the App_Data directory of the application does not exist, the Web server account must have read and write permissions on the application directory. This is because if the App_Data directory does not exist, the Web server account will automatically create it.
  2. If the App_Data directory of the application already exists, the Web server account requires read and write permissions on the App_Data directory of the application. This is necessary because the Web Server account will try to confirm that the SQL Server Express database is already in the App_Data directory of the application. If the read permission on the App_Data directory is revoked from the Web Server account, the provider cannot correctly determine whether the SQL Server Express database already exists. If the provider tries to create a copy of an existing database, an error occurs. Write access permissions are required because Web Server account creden。 are required when you create a new database.
  3. SQL Server Express must be installed on the computer.
  4. The process ID of the Web server account must have a local user configuration file. For more information about how to create a local user configuration file for a computer account and domain account, see the README document.

Source error:

An unhandled exception is generated during the execution of the current Web request. You can use the following exception stack trace information to determine the cause and location of the exception.

Stack trace:

[SqlException (0x80131904): An error occurred while establishing a connection with the server. When you connect to SQL Server 2005, the default setting does not allow remote connection to SQL Server may cause this failure. (Provider: SQL network interface, error: 26-An error occurred while locating the specified server/instance)] System. data. sqlClient. sqlInternalConnection. onError (SqlException exception, Boolean breakConnection) + 173 System. data. sqlClient. tdsParser. throwExceptionAndWarning (TdsParserStateObject stateObj) + 199 System. data. sqlClient. tdsParser. connect (Boolean & useFailoverPartner, Boolean & failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup) + 1069 System. data. sqlClient. sqlInternalConnectionTds. openLoginEnlist (SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) + 606 System. data. sqlClient. sqlInter NalConnectionTds .. ctor (DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) + 193 System. data. sqlClient. sqlConnectionFactory. createConnection (DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) + 219 System. data. provide RBase. dbConnectionFactory. createNonPooledConnection (DbConnection owningConnection, DbConnectionPoolGroup poolGroup) + 27 System. data. providerBase. dbConnectionFactory. getConnection (DbConnection owningConnection) + 49 System. data. providerBase. dbConnectionClosed. openConnection (DbConnection outerConnection, DbConnectionFactory connectionFactory) + 89 System. data. sqlClient. sqlConnection. open () + 160 System. Web. management. sqlServices. getSqlConnection (String server, String user, String password, Boolean trusted, String connectionString) + 67 [HttpException (0x80004005): unable to connect to the SQL Server database.] System. web. management. sqlServices. getSqlConnection (String server, String user, String password, Boolean trusted, String connectionString) + 123 System. web. management. sqlServices. setupApplicationServices (String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) + 89 System. web. management. sqlServices. install (String database, String dbFileName, String connectionString) + 26 System. web. dataAccess. sqlConnectionHelper. createMdfFile (String fullFileName, String dataDir, String connectionString) + 388

Version:Microsoft. NET Framework Version: 2.0.50727.42; ASP. NET version: 2.0.50727.42

After some searches, I finally got the answer to the question.
Originally, when using personalized services for WebPart, you must configure a connection string in the web. config file.
The solution is as follows:
The first method is to disable the personalized service and modify the attributes of WebPartManager: Set Personalization-> Enabled to False.

To use personalized services, you must use the following method:
1. Run C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 \ aspnet_regsql.exe
Follow the prompts to install the database.

2. Add a connection string under connectionStrings in the web. config file: <remove name = "LocalSqlServer"/>
<Add name = "LocalSqlServer" connectionString = "Data Source = localhost; Initial Catalog = aspnetdb; Persist Security Info = True; User ID = sa; Password ="
ProviderName = "System. Data. SqlClient"/>

This configuration overwrites the default connection string and uses the custom connection string.

Finally, the problem is solved.

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.