SqlConnection connection method

Source: Internet
Author: User

SQL server2000
(1) Local connection
Here is the local connection sql2000, using the following two connection strings

String Source = @ "Server =. Kingsql;database = Northwind; Integrated SECURITY=SSPI ";

String Source = @ "Server =. Kingsql;database = Northwind; UID = sa; PWD = sa ";
(2) Remote connection
The first step is to ensure that the client connects to the SQL Server.
Specify the following:
1) Ping server IP test connectivity or not
This is actually to see if the physical connection to the remote SQL Server 2000 Server exists. If not, check the network to see the configuration and, of course, make sure that the IP of the remote SQL Server 2000 server is spelled correctly.

2) Enter the Telnet server IP port under DOS or command line to see if it can be connected
such as: Telnet 202.114.100.100 1433
Typically, the port value is 1433 because 1433 is the default listening port for TCP/IP for SQL Server 2000. If there is a problem, this step usually goes wrong. The usual hint is "... Unable to open connection, connection failed. "
If there is a problem with this step, you should check the following options.
1 Check whether the remote server started the SQL Server 2000 service. If not, it starts.
2 Check that the TCP/IP protocol is not enabled on the server side because remote connections (via the Internet) are required by this co-check method is to open the Microsoft SQL server-> Server Network Utility, Start menu, programs on the server, See if there is a TCP/IP protocol in the enabled Protocol, and if not, enable it.
3 Check that the TCP/IP port of the server is configured as 1433 port. In the Server Network Utility, check the TCP/IP properties in the Enable protocol, make sure the default port is 1433, and the Hide server check box is not checked.
In fact, if the default port is modified, it is also possible, but when the client does the Telnet test, the server port number must be the same as the port number configured by the server. If the Hide Server check box is checked, it means that the client cannot enumerate the server to see this server, but does not affect the connection, but the TCP/IP protocol default port will be implicitly modified to 2433, when the client connection must be changed accordingly.
4 If the server-side operating system has SP2 patch, you have to configure the Windows Firewall, to open 1433 ports to it, usually in the test can be directly shut down the Windows Firewall (the other firewall is also turned off the best).
5 Check if the server is listening on port 1433. If the server is not listening on port 1433 on a TCP connection, it is not connected. The check method is to enter Netstat-a-N or Netstat-an under the DOS or command line of the server, and see if there are items like TCP 127.0.0.1 1433 listening in the results list. If not, you will typically need to make at least SP3 patches to SQL Server 2000. In fact, start the Query Analyzer on the server side, enter the SELECT @ @version can see the version number, the version number in 8.0.2039 or less needs to be patched. If the above is not a problem, then you do telnet server IP 1433 test, you will see the screen flash after the cursor is flashing in the upper left corner. Congratulations, you can start right away. The Enterprise Manager or Query Analyzer is connected.

The general wording can be enough, for us these rookie speaking is enough, as for the complex later in writing,

SqlConnection conn = new SqlConnection ("server=.;D Atabase=northwind; uid=sa;pwd=123; ");
Server=.; Destination server IP is used locally. (Local),
Database name
Uid, user ID, username of connection database
PWD Password is the password to connect to the database
If not, do not write otherwise error

SqlConnection connection method

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.