Start Visual Studio, create a new Web project
Click to open the Web. config file in the project directory,
Locate the node and add the database configuration
The ASPX interface creates a new button and a text box to test the database connection.
Where button adds a click event
The button corresponds to the Click event by adding the following code (the code is used only for test demonstrations, and the rigor is not considered)
protected void Button1_Click (object sender, EventArgs e)
{
string setting = "MyDB";
var connstring = system.web.configuration.webconfigurationmanager.connectionstrings[setting];
SqlConnection conn = new SqlConnection (connstring.connectionstring);
TextBox1.Text = conn. ToString ();
}
Right-click to view the page in the browser,
Click button if the database connection is successful, the current connection success prompt is displayed in the text box
"System.Data.SqlClient.SqlConnection"
Asp. NET database connection