Abstract: today, I want to write a Windows Service Program in C #, which connects to an SQL Server 2003 database on Windows 2000 Server and uses SQL Server for authentication. Common programs can be connected, but Windows service programs cannot be connected.
Later, I checked the information and found a solution. Share it with you.
Three-step solution:
1. Create a user on the Server and configure the SQL Server database access permission.
2. Create an identical user on the client.
3. The service program logs on with the client user you just created.
Done!
Keywords: SSPI, Integrated Security, SQL Server and Windows, authentication, SQL Server does not exist, or access is denied.
Reference documents: Windows Authentication and SQL Server
Http://msdn.microsoft.com/library/chs/default.asp? Url =/library/CHS/f_and_m/html/vxconwindowsauthentication. asp
Visual Studio example: Fitch and Mather 7.0
Windows Authentication and SQL Server
Fitch and Mather 7.0 access SQL Server through SQL Server Authentication. Although it is very simple and provides easy-to-understand examples, it is not the safest method. Fitch and Mather 7.0 stores the connection string (including database creden。) in two locations: the Web. config file and the COM + Admin directory (in the constructor string of the FMStocks7.GAM. 7 component ). By default, any user can read these two locations, so it is easy to inadvertently disclose confidential information (creden ).
A better solution is to use Windows integrated security. First, the Windows identification that can be recognized by both the Internet Information Service (IIS) Server and the SQL Server database is required. There are two options:
· Domain account
If the server is part of the domain and the administrator can create the domain account of the application, this is the best method.
· Local Account with synchronization Password