How does vs connect to the sql server database?

1. Configure in web.config and then connect to the database

(1) web.config file: add between and

Three configuration methods:

1. Windows authentication, connect to sql server database:

2. Windows authentication, connect to vs database:

3. sql server authentication, connect to sql server database:

The way to take the word concatenation string:

1、protected static string connectionString = ConfigurationManager.ConnectionStrings[“字符串名称”].ConnectionString;

2、string connectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings[“字符串名称”].ConnectionString;

(2) web.config file: add between and
Configuration method:

How does vs connect to the sql server database? -lt408805039-Oh that's it

The way to take the word concatenation string:

string connectionString =configurationsettings.appsettings["string name"];

The difference between appSettings and connectionStrings:

(1) appSettings is commonly used in 2003, connectionStrings is commonly used in 2005;

(2) The benefits of using connectionStrings:

First, you can encrypt the connection string by using an encryption tool of MS;

Second, you can directly bind the data source control without writing code to read it out and assign it to the control;

Third, you can easily change the database platform, such as changing to an Oracle database, you only need to modify the providerName.

2. Directly quote in the web page and connect to the database:

1. string connString = "server=localhost;database=database name;user id=user name;pwd=password;";

Or the upstream code is: string connstring = "Data source=localhost;database=database name;user id=user name;pwd=password;";

2、SqlConnection con = new SqlConnection(connstring);

3、con.Open();

Guess you like

Origin blog.csdn.net/qq_41661800/article/details/105505264