using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
Using System. Web. UI.
Using System. Web. UI. WebControls;
using System.Data;
using System.Data.SqlClient;
The namespace WebApplication9
{
Public partial class serve: System. Web. UI. Page
{
Private void page_load (object sender, EventArgs e)
{
Try {
String connstring="server=. The database=sql2008. Cs. Dbo; User ID=reny; Password=123456 ";
SqlConnection sqlConn=new sqlConnection (connstring);
SqlConn. The Open ();
If (sqlConn. State==ConnectionState. Open)
LblResult. Text="connect to the database success";
}
The catch (Exception ex) {
LblResult. Text="abnormal" connection;
}
}
}
}
CodePudding user response:
Unable to connect to you also don't know why is so prompt "abnormal" connection?At the very least, you have to put the ex output to see what specific reason?
Try catch let you lost the ability to debug...
CodePudding user response:
Press # 1 wish, the ex. The Message and stack information printed,CodePudding user response:
Don't understand what you mean?CodePudding user response:
Copy the code, don't even know, what is the try big probability may be haven't installed the database, or the default installation, authentication mode or Windows authentication didn't change, or the account has not been built,CodePudding user response:
Database open look at first, according to the above account password can connectCodePudding user response:
Try{
}
the catch (Exception e)
{
Throw;
}
Look at what the problem, posted the question
CodePudding user response:
Suggest lblResult. Text="connection abnormal -- -- -- -- -- -- --" + ex. The Message;CodePudding user response:
Cannot appear database connection information of successCodePudding user response:
The database has been built and imported into visual studioCodePudding user response:
Can you connect the database, the connection string is very important,Ensure correct connection string to say again first:
https://blog.csdn.net/yenange/article/details/77026214