Some preliminary experiences after solving some basic problems during SQL server connection

Source: Internet
Author: User
The student made a question bank system and used ASP applications written in C #. Program , The database uses SQL
Server2000, let me have a look. An error occurs when it is placed on the server. After repeated adjustments, we found the solution, which is actually very simple. Looking back and looking at it, I found that the SQL
Server connection statements and insufficient user permissions. Next I will share some of my experiences and relevant information I found on the Internet, so that it is superficial to learn from later users.

1. The connection method of SQL Server is based on the local server (localhost) and database (northwind). The following connection methods are available: 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.
Log on to the database as a user. If this parameter is set to true, yes, or
Sspi, which does not contain UID and PWD. It will 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.

For more string connection instructions, see msdn:
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/cpref/html/frlrfsystemdatasqlclientsqlconnectionclassconnectionstringtopic. asp

There should be no problem after writing the connection string skillfully. I am looking at other people's programs. To tell the truth, 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 mode to connect to the database, and SA user connection may have security risks, I think it is mainly because the installation of SQL
Server, the SA password is often set to NULL 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
SQL
Server access users can only pass windows integration verification, and set the SA security password to enhance database security. Of course, after Windows integration verification, the database performance and
The access flexibility is bound to be affected. administrators can set different authentication methods for each database, without having to set a unified approach for SQL Server.

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.