Lm th? no ? s? d?ng tham s? tn my ch? trong m?t chu?i k?t n?i ? ch? ?nh th vi?n m?ng l?i khch hng

D?ch tiu ? D?ch tiu ?
ID c?a bi: 313295 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

? Trang ny

TM T?T

Bi vi?t ny m t? cch l?p tr?nh ch? ?nh cc th vi?n m?ng l?i khch hng trong chu?i k?t n?i khi b?n k?t n?i t?i m?t SQL My ch? c s? d? li?u.

Trong cc thnh ph?n d? li?u Microsoft Access (MDAC) 2.6 v sau , b?n c th? ch? ?nh cc khch hng truy c?p vo th vi?n b?ng cch s? d?ng cc tn my ch? tham s? trong k?t n?i chu?i. V? v?y, b?n c th? ch? ?nh m?t th vi?n truy c?p khch hng c? th? khi b?n ang thc ?y b?i m?t ?ng d?ng cho tn h? ph?c v? m k?t n?i. Hnh vi ny c th? r?t h?u ch khi b?n ang th? nghi?m v g? r?i cc v?n ? k?t n?i cho SQL Server.

V d?, b?n c th? s? d?ng cc Osql Ti?n ch d?ng l?nh ? k?t n?i v?i SQL Server v p bu?c n ? s? d?ng th vi?n m?ng TCP/IP:
osql -Stcp:myServer,portNumber -E
				

M?u m?

Cc sau y Microsoft Visual C#.NET m? m?u ch?ng t? lm th? no ? thi?t l?p k?t n?i chu?i. K?t n?i chu?i c cng m?t ?nh d?ng khng phn bi?t c?a ngn ng? m b?n s? d?ng:
using System;
using System.Data;
using System.Data.SqlClient;

namespace getCurrentProtocol
{
	/// <summary>
	/// Main Application Driver Class
	/// </summary>
	class Driver
	{
		static void Main(string[] args)
		{
			string sCxn = "server=myServer;Integrated Security=SSPI; database=master";
			//string sCxn = "server=np:myServer;Integrated Security=SSPI; database=master";
			//string sCxn = "server=tcp:myServer;Integrated Security=SSPI; database=master";
			//string sCxn = "server=rpc:myServer;Integrated Security=SSPI; database=master";
			//string sCxn = "server=lpc:myServer;Integrated Security=SSPI; database=master";
			string sCmd = "SELECT net_library from sysprocesses where spid=@@spid";
			SqlConnection cxn = new SqlConnection(sCxn);
			SqlCommand sqlCmd = new SqlCommand(sCmd, cxn);
			SqlDataAdapter sqlDa = new SqlDataAdapter(sCmd, cxn);
			DataTable dt = new DataTable();
			try 
			{
				sqlDa.Fill(dt);
				Console.WriteLine("Hit ENTER to continue ...");
				Console.ReadLine();
				foreach (DataRow dr in dt.Rows)
					Console.WriteLine(dr["net_library"]);
			} 
			catch (SqlException e)
			{
				Console.WriteLine(e.StackTrace);
				Console.WriteLine("SQL Error Number: " + e.Number);
				Console.WriteLine("SQL Error Message: " + e.Message);
				
			}
		}
	}
} 
				
Lu ? cc chu?i k?t n?i v ?c bi?t l gi tr? c?a cc h? ph?c v? tham s?:
string sCxn = "server=myServer;Integrated Security=SSPI; database=northwind"
				

S? d?ng m?u m? v?i cc m?ng l?i cc th vi?n

M?u m? sau y ch?ng minh lm th? no ? s? d?ng gi tr? c?a cc h? ph?c v? tham s? ? xc ?nh cc m?ng th vi?n:
  • TCP/IP:
    server=tcp:hostname
    B?n c th? ty ch?n xc ?nh s? hi?u c?ng c? th?. Theo m?c ?nh, c?ng l 1433.
    server=tcp:hostname, portNumber
  • ?c ?t tn theo ?ng ?ng:
    server=np:hostname
    B?n c th? ty ch?n ch? m?t c? th? tn l ?ng ?ng.
    server=np:\\hostname\pipe\pipeName
    Theo m?c ?nh, tn ?ng ?ng ny l sql\query. N?u b?n k?t n?i v?i m?t tn V d?, ?ng tn l i?n h?nh trong ?nh d?ng sau:
    MSSQL$ instnaceName\sql\query
  • Multiprotocol:
    server=rpc:hostname
    B?n c th? ty ch?n xc ?nh giao th?c n?m bn d?i.
    server=rpc:hostname, protocol
    Gi tr? m?c ?nh c?a giao th?c ti?m ?n ?c xc ?nh b?i cc thi?t ?t h? i?u hnh ni m?t giao th?c c th? c b?t k? m?t trong nh?ng i?u sau y gi tr?:
    Thu g?n b?ng nyBung r?ng b?ng ny
    Gia triGiao th?c ti?m ?n
    ncacn_np?c ?t tn theo ?ng ?ng
    ncacn_ip_tcpKi?m sot truy?n t?i Protocol/Internet Protocol (TCP/IP)
    ncacn_nb_nbH? th?ng m?ng c b?n vo/ra (NetBIOS) qua NetBIOS nng cao giao di?n ng?i dng (NetBEUI)
    ncacn_spxSequenced Packet Exchange (SPX)
    ncacn_vns_sppCy a dy leo
    ncadg_ip_udpUDP (UDP) datagram TCP/IP
    ncadg_ipxInternetwork gi Exchange (IPX) datagram IPX
    ncalrpcCu?c g?i th? t?c ?a phng

  • B? nh? chia s?:
    server=lpc:hostname
  • NWlink IPX/SPX:
    server=spx:hostname
  • Cy a dy leo:
    server=vines:hostname
  • Apple Talk:
    server=adsp:hostname

THAM KH?O

? bi?t thm thng tin, gh thm Web site sau c?a Microsoft:

http://MSDN.Microsoft.com/en-US/Library/aa470051.aspx

Thu?c tnh

ID c?a bi: 313295 - L?n xem xt sau cng: 27 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft SQL Server 2000 Standard Edition
  • Microsoft SQL Server 2000 64-bit Edition
  • Microsoft Data Access Components 2.6
  • Microsoft Data Access Components 2.6 Service Pack 1
  • Microsoft Data Access Components 2.7
  • Microsoft SQL Server 2005 Standard Edition
  • Microsoft SQL Server 2005 Express Edition
  • Microsoft SQL Server 2005 Developer Edition
  • Microsoft SQL Server 2005 Enterprise Edition
  • Microsoft SQL Server 2005 Workgroup Edition
T? kha:
kbhowtomaster kbmt KB313295 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:313295

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com