Some basic questions about SQL server connection

Source: Internet
Author: User
1. The connection method of SQL Server is based on the local server (localhost) and database (northwind). The following connection methods can be used: sqlconnection conn = new sqlconnection ("Server = localhost; integrated Security = sspi; database = northwind "); sqlconnection conn = new sqlconnection (" Data Source = localhost; Integrated Security = sspi; initial catalog = northwind ;"); sqlconnection conn = new sqlconnection ("Data Source = localhost; initial catalog = northwind; Integrated Security = sspi; persist Security info = false; workstation id = xurui; packet size = 4096; ");
Sqlconnection myconn = new sqlconnection ("Persist Security info = false; Integrated Security = sspi; database = northwind; server = localhost ");
Sqlconnection conn = new sqlconnection ("uid = sa; Pwd = ***; initial catalog = northwind; Data Source = localhost; Connect timeout = 900 ");

TIPS: A. server and database, data source and initial catalog can be used in pairs and can be replaced with each other (Laugh)
B. the default value of integrated security is false. UID and PWD must be provided to log on to the database as an SQL Server user. If it is set to true, yes, or sspi, UID and PWD cannot appear, log on to the database in the Windows user province. It is strongly recommended that the latter form be used for higher security.
C. Integrated Security and persist Security info appear at the same time. The latter is set to false to ensure information security.

There should be no problem after writing the connection string skillfully. I will look at other people'sProgramTo be honest, some things are really unclear. But after the connection fails, you have to solve it. Therefore, you must understand the meaning of these keywords and modify them before testing.

2. SQL Server user settings
Question 1: Use a connection string
Sqlconnection conn = new sqlconnection ("uid = sa; Pwd = ***; initial catalog = northwind; Data Source = localhost; Connect timeout = 900 ");
Error:
User "sa" Login Failed, no trusted SQL server connection
Find the solution after checking the information:
Cause: the SQL Server authentication method needs to be set to a mix of SQL Server Authentication and Windows Integration authentication. If you are only set to the latter method, the above problems will occur.
Solution: run the SQL Server Enterprise Manager, click the server, right-click the server, select Properties, select security, and change the authentication method.
Problem 2: Use a connection string
Sqlconnection conn = new sqlconnection ("Data Source = localhost; Integrated Security = sspi; initial catalog = northwind ;");
Error:
User "computername \ iwam_servername" Login Failed
Cause: the SQL Server login user does not include iwam_servername
Solution: run the SQL Server Enterprise Manager, click the server, select Security, select login, add iwam_servername to the new login, and assign corresponding permissions. For example, you can only access the northwind database, set the database role to public and db_owner.

3. Connection Security

It is best to use sspi integrated security to connect to the database, while SA user connection may pose security risks. I think it is mainly because when installing SQL Server, the SA password is often set to be empty for access convenience. Once a hacker makes SA an administrator, all access permissions to the system can be obtained. For database security, you can set the SQL server access user to pass the Windows integrated verification, set the SA security password, and enhance the database security. Of course, after being set to Windows integration verification, the database performance and access flexibility will inevitably be affected. The administrator can set different verification methods for each database, instead of setting SQL server in a unified manner.

If the port is not the default one, enter Server = localhost and port number.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.