Using an IP Address to Connect to SQL Server
Số trang: 3
Loại file: pdf
Dung lượng: 15.34 KB
Lượt xem: 13
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
[ Team LiB ] Recipe 1.6 Using an IP Address to Connect to SQL Server Problem You want to connect to a SQL Server using its IP address instead of its server name. Solution Use the Network Address and Network Library attributes of the connection string
Nội dung trích xuất từ tài liệu:
Using an IP Address to Connect to SQL Server [ Team LiB ]Recipe 1.6 Using an IP Address to Connect to SQL ServerProblemYou want to connect to a SQL Server using its IP address instead of its server name.SolutionUse the Network Address and Network Library attributes of the connection string.The sample code contains a single event handler:Connect Button.Click Creates and opens a connection to a SQL Server using its IP address. Information about the SQL Server is displayed from the properties of the SqlConnection object.The C# code is shown in Example 1-5.Example 1-5. File: ConnectSqlServerIpAddressForm.cs// Namespaces, variables, and constantsusing System;using System.Data.SqlClient;// . . .private void connectButton_Click(object sender, System.EventArgs e){ String connString = Network Library=dbmssocn;Network Address=127.0.0.1; + Integrated security=SSPI;Initial Catalog=Northwind; SqlConnection conn = new SqlConnection(connString); conn.Open( ); // Return some information about the server. resultTextBox.Text = ConnectionState = + conn.State + Environment.NewLine + DataSource = + conn.DataSource + Environment.NewLine + ServerVersion = + conn.ServerVersion + Environment.NewLine; conn.Close( ); resultTextBox.Text += ConnectionState = + conn.State;}DiscussionSQL Server network libraries are dynamic-link libraries (DLLs) that perform networkoperations required for client computers and SQL Server computers to communicate. Aserver can monitor multiple libraries simultaneously; the only requirement is that eachnetwork library to be monitored is installed and configured.Available network libraries for SQL Server 2000 include:AppleTalk ADSP Allows Apple Macintosh to communicate with SQL Server using native AppleTalk protocol.Banyan VINES Supports Banyan VINES Sequenced Packet Protocol (SPP) across Banyan VINES IP network protocol.Multiprotocol Automatically chooses the first available network protocol to establish a connection generally with performance comparable to using a native network library. TCP/IP Sockets, NWLink IPX/SPX, and Named Pipes are supported.Named Pipes Interprocess communication (IPC) mechanism provided by SQL Server for communication between clients and servers.NWLink IPX/SPX The native protocol of Novell Netware networks.TCP/IP Sockets Uses standard Windows sockets to communicate across the TCP/IP protocol.Clustered installations of SQL Server support only Named Pipes and TCP/IP protocols.AppleTalk, Banyan Vines, and Multiprotocol protocols are unavailable if namedinstances are installed on the server.For more information about network libraries and configuring network libraries, seeMicrosoft SQL Server Books Online.The use of the SQL Server TCP/IP Sockets improves performance and scalability withhigh volumes of data. It avoids some security issues associated with named pipes. Aswith any protocol, the client and the server must be configured to use TCP/IP.To connect to SQL Server using an IP address, the TCP/IP network library must be usedto connect to the SQL Server. This is done by specifying the library in the connectionstring as either the attribute Net or Network Library with a value of dbmssocn. Specifythe IP address using the Data Source, Server, Address, Addr, or Network Addressparameter. The following connection string demonstrates using an IP address to specifythe data source:Network Library=dbmssocn;Network Address=127.0.0.1; Integrated security=SSPI;Initial Catalog=NorthwindIn the example, the IP address is the local machine. This could also be specified as(local). To specify a SQL Server other than a local instance, specify the IP address of thecomputer on which SQL Server is installed.Default instances of SQL Server listen on port 1433. Named instances of SQL Serverdynamically assign a port number when they are first started. The example above doesnot specify the port number and therefore uses the default port 1433 of the SQL Server. Ifthe SQL Server is configured to listen on another port, specify the port number followingthe IP address specified by the Network Address attribute separated by a comma asshown in the following snippet, which connects to a local SQL Server listening on port1450:Network Address=(local),1450[ Team LiB ]
Nội dung trích xuất từ tài liệu:
Using an IP Address to Connect to SQL Server [ Team LiB ]Recipe 1.6 Using an IP Address to Connect to SQL ServerProblemYou want to connect to a SQL Server using its IP address instead of its server name.SolutionUse the Network Address and Network Library attributes of the connection string.The sample code contains a single event handler:Connect Button.Click Creates and opens a connection to a SQL Server using its IP address. Information about the SQL Server is displayed from the properties of the SqlConnection object.The C# code is shown in Example 1-5.Example 1-5. File: ConnectSqlServerIpAddressForm.cs// Namespaces, variables, and constantsusing System;using System.Data.SqlClient;// . . .private void connectButton_Click(object sender, System.EventArgs e){ String connString = Network Library=dbmssocn;Network Address=127.0.0.1; + Integrated security=SSPI;Initial Catalog=Northwind; SqlConnection conn = new SqlConnection(connString); conn.Open( ); // Return some information about the server. resultTextBox.Text = ConnectionState = + conn.State + Environment.NewLine + DataSource = + conn.DataSource + Environment.NewLine + ServerVersion = + conn.ServerVersion + Environment.NewLine; conn.Close( ); resultTextBox.Text += ConnectionState = + conn.State;}DiscussionSQL Server network libraries are dynamic-link libraries (DLLs) that perform networkoperations required for client computers and SQL Server computers to communicate. Aserver can monitor multiple libraries simultaneously; the only requirement is that eachnetwork library to be monitored is installed and configured.Available network libraries for SQL Server 2000 include:AppleTalk ADSP Allows Apple Macintosh to communicate with SQL Server using native AppleTalk protocol.Banyan VINES Supports Banyan VINES Sequenced Packet Protocol (SPP) across Banyan VINES IP network protocol.Multiprotocol Automatically chooses the first available network protocol to establish a connection generally with performance comparable to using a native network library. TCP/IP Sockets, NWLink IPX/SPX, and Named Pipes are supported.Named Pipes Interprocess communication (IPC) mechanism provided by SQL Server for communication between clients and servers.NWLink IPX/SPX The native protocol of Novell Netware networks.TCP/IP Sockets Uses standard Windows sockets to communicate across the TCP/IP protocol.Clustered installations of SQL Server support only Named Pipes and TCP/IP protocols.AppleTalk, Banyan Vines, and Multiprotocol protocols are unavailable if namedinstances are installed on the server.For more information about network libraries and configuring network libraries, seeMicrosoft SQL Server Books Online.The use of the SQL Server TCP/IP Sockets improves performance and scalability withhigh volumes of data. It avoids some security issues associated with named pipes. Aswith any protocol, the client and the server must be configured to use TCP/IP.To connect to SQL Server using an IP address, the TCP/IP network library must be usedto connect to the SQL Server. This is done by specifying the library in the connectionstring as either the attribute Net or Network Library with a value of dbmssocn. Specifythe IP address using the Data Source, Server, Address, Addr, or Network Addressparameter. The following connection string demonstrates using an IP address to specifythe data source:Network Library=dbmssocn;Network Address=127.0.0.1; Integrated security=SSPI;Initial Catalog=NorthwindIn the example, the IP address is the local machine. This could also be specified as(local). To specify a SQL Server other than a local instance, specify the IP address of thecomputer on which SQL Server is installed.Default instances of SQL Server listen on port 1433. Named instances of SQL Serverdynamically assign a port number when they are first started. The example above doesnot specify the port number and therefore uses the default port 1433 of the SQL Server. Ifthe SQL Server is configured to listen on another port, specify the port number followingthe IP address specified by the Network Address attribute separated by a comma asshown in the following snippet, which connects to a local SQL Server listening on port1450:Network Address=(local),1450[ Team LiB ]
Tìm kiếm theo từ khóa liên quan:
công nghệ thông tin kỹ thuật lập trình Oreilly Ado Dot Net Cookbook Ebook-Lib Using an IP Address to Connect to SQL ServerTài liệu liên quan:
-
52 trang 434 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 321 0 0 -
74 trang 304 0 0
-
96 trang 299 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 293 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 286 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 277 0 0 -
Tài liệu hướng dẫn sử dụng thư điện tử tài nguyên và môi trường
72 trang 270 0 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 270 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 269 1 0