The previous article only writes the connection code of the database SQL Server connection mode here to add a connection to Windows Authentication mode:
about how vs Connect SQL Server database Windows Authentication works:
The top menu in the 01.VS window selects data in turn
02. Add a new data source
03. Then select the database and click Next
As shown in the following:
04. Select the data set and click Next
As shown in the following:
05. Click New Connection, pop up the dialog box
As shown in the following:
06. The data source is displayed as Microsoft SQL Server SqlClient If you do not need to click Change modification to Microsoft SQL Server SqlClient; server name fill SQL Server Server name in Windows Authentication mode; Log on to the server select Use Windows Authentication; Connect to a database Select the first item, select or fill in the database that you want to connect with.
07. Click the bottom left corner to test the connection, and the popup dialog shows that the test connection was successful. Then click OK to close the dialog box and click OK.
As shown in the following:
08. Here is a connection string click on the front + sign
As shown in the following:
09. Tap the plus sign to expand, copy the resulting string after the point is canceled, and then paste the location of the database connection string in the previous C # code
Comparison of connection strings in two ways:
SQL Server Authentication: string constring= "server=.database=teaching;uid=sa;pwd=123456";
Windows Authentication: String constr= "Data source=.;i Nitial catalog=teaching;integrated security=true ";
Clumsy birds have essay: code that connects to SQL Server database (Windows authentication method supplement) in ADO