Save database connection information in ASP.NET

xiaoxiao2021-03-06  95

1. In ASP.NET, you can save database connection information in the web.config file.

Such as: Editing Web.config Files

The method of reading is as follows

Using system.configuration;

String mysqlconnectionstring = configurationSettings.appsettings ["connectionstring"];

You can read the data connection information to the string mysqlConnectionstring.

2, you can save the database connection information in a class file, use a static variable to store.

Such as:

Public Class DataAccess () {// // Todo: Add Construction Function Logic //} ///

/// Database Connection String /// Public Stianstring { Get {return "Workstation ID = XYWQ; packet size = 4096; user ID = sa; data source = xywq; persist security info = true; initial catalog = it; password = lg8280";}}}

When using, after applying the namespace, you can directly access the database connection string directly with DataAccess.connectionstring.

Such as: SqlConnnection SqlConn = New SqlConnection (dataaccess.connectionstring);

转载请注明原文地址:https://www.9cbs.com/read-122768.html

New Post(0)