SqlConnection.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. //
  2. // System.Data.SqlClient.SqlConnection.cs
  3. //
  4. // Authors:
  5. // Rodrigo Moya ([email protected])
  6. // Daniel Morgan ([email protected])
  7. // Tim Coleman ([email protected])
  8. // Phillip Jerkins ([email protected])
  9. // Diego Caravana ([email protected])
  10. //
  11. // Copyright (C) Ximian, Inc 2002
  12. // Copyright (C) Daniel Morgan 2002, 2003
  13. // Copyright (C) Tim Coleman, 2002, 2003
  14. // Copyright (C) Phillip Jerkins, 2003
  15. //
  16. using Mono.Data.Tds;
  17. using Mono.Data.Tds.Protocol;
  18. using System;
  19. using System.Collections;
  20. using System.Collections.Specialized;
  21. using System.ComponentModel;
  22. using System.Data;
  23. using System.Data.Common;
  24. using System.EnterpriseServices;
  25. using System.Net;
  26. using System.Net.Sockets;
  27. using System.Text;
  28. using System.Xml;
  29. namespace System.Data.SqlClient {
  30. [DefaultEvent ("InfoMessage")]
  31. public sealed class SqlConnection : Component, IDbConnection, ICloneable
  32. {
  33. #region Fields
  34. bool disposed = false;
  35. // The set of SQL connection pools
  36. static Hashtable SqlConnectionPools = new Hashtable ();
  37. // The current connection pool
  38. SqlConnectionPool pool;
  39. // The connection string that identifies this connection
  40. string connectionString = null;
  41. // The transaction object for the current transaction
  42. SqlTransaction transaction = null;
  43. // Connection parameters
  44. TdsConnectionParameters parms = new TdsConnectionParameters ();
  45. bool connectionReset;
  46. bool pooling;
  47. string dataSource;
  48. int connectionTimeout;
  49. int minPoolSize;
  50. int maxPoolSize;
  51. int packetSize;
  52. int port = 1433;
  53. // The current state
  54. ConnectionState state = ConnectionState.Closed;
  55. SqlDataReader dataReader = null;
  56. XmlReader xmlReader = null;
  57. // The TDS object
  58. ITds tds;
  59. #endregion // Fields
  60. #region Constructors
  61. public SqlConnection ()
  62. : this (String.Empty)
  63. {
  64. }
  65. public SqlConnection (string connectionString)
  66. {
  67. ConnectionString = connectionString;
  68. }
  69. #endregion // Constructors
  70. #region Properties
  71. [DataCategory ("Data")]
  72. [DataSysDescription ("Information used to connect to a DataSource, such as 'Data Source=x;Initial Catalog=x;Integrated Security=SSPI'.")]
  73. [DefaultValue ("")]
  74. [RecommendedAsConfigurable (true)]
  75. [RefreshProperties (RefreshProperties.All)]
  76. public string ConnectionString {
  77. get { return connectionString; }
  78. set { SetConnectionString (value); }
  79. }
  80. [DataSysDescription ("Current connection timeout value, 'Connect Timeout=X' in the ConnectionString.")]
  81. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  82. public int ConnectionTimeout {
  83. get { return connectionTimeout; }
  84. }
  85. [DataSysDescription ("Current SQL Server database, 'Initial Catalog=X' in the ConnectionString.")]
  86. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  87. public string Database {
  88. get { return tds.Database; }
  89. }
  90. internal SqlDataReader DataReader {
  91. get { return dataReader; }
  92. set { dataReader = value; }
  93. }
  94. [DataSysDescription ("Current SqlServer that the connection is opened to, 'Data Source=X' in the ConnectionString.")]
  95. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  96. public string DataSource {
  97. get { return dataSource; }
  98. }
  99. [DataSysDescription ("Network packet size, 'Packet Size=x' in the ConnectionString.")]
  100. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  101. public int PacketSize {
  102. get { return packetSize; }
  103. }
  104. [Browsable (false)]
  105. [DataSysDescription ("Version of the SQL Server accessed by the SqlConnection.")]
  106. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  107. public string ServerVersion {
  108. get { return tds.ServerVersion; }
  109. }
  110. [Browsable (false)]
  111. [DataSysDescription ("The ConnectionState indicating whether the connection is open or closed.")]
  112. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  113. public ConnectionState State {
  114. get { return state; }
  115. }
  116. internal ITds Tds {
  117. get { return tds; }
  118. }
  119. internal SqlTransaction Transaction {
  120. get { return transaction; }
  121. set { transaction = value; }
  122. }
  123. [DataSysDescription ("Workstation Id, 'Workstation Id=x' in the ConnectionString.")]
  124. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  125. public string WorkstationId {
  126. get { return parms.Hostname; }
  127. }
  128. internal XmlReader XmlReader {
  129. get { return xmlReader; }
  130. set { xmlReader = value; }
  131. }
  132. #endregion // Properties
  133. #region Events
  134. [DataCategory ("InfoMessage")]
  135. [DataSysDescription ("Event triggered when messages arrive from the DataSource.")]
  136. public event SqlInfoMessageEventHandler InfoMessage;
  137. [DataCategory ("StateChange")]
  138. [DataSysDescription ("Event triggered when the connection changes state.")]
  139. public event StateChangeEventHandler StateChange;
  140. #endregion // Events
  141. #region Delegates
  142. private void ErrorHandler (object sender, TdsInternalErrorMessageEventArgs e)
  143. {
  144. throw new SqlException (e.Class, e.LineNumber, e.Message, e.Number, e.Procedure, e.Server, "Mono SqlClient Data Provider", e.State);
  145. }
  146. private void MessageHandler (object sender, TdsInternalInfoMessageEventArgs e)
  147. {
  148. OnSqlInfoMessage (CreateSqlInfoMessageEvent (e.Errors));
  149. }
  150. #endregion // Delegates
  151. #region Methods
  152. public SqlTransaction BeginTransaction ()
  153. {
  154. return BeginTransaction (IsolationLevel.ReadCommitted, String.Empty);
  155. }
  156. public SqlTransaction BeginTransaction (IsolationLevel iso)
  157. {
  158. return BeginTransaction (iso, String.Empty);
  159. }
  160. public SqlTransaction BeginTransaction (string transactionName)
  161. {
  162. return BeginTransaction (IsolationLevel.ReadCommitted, transactionName);
  163. }
  164. public SqlTransaction BeginTransaction (IsolationLevel iso, string transactionName)
  165. {
  166. if (state == ConnectionState.Closed)
  167. throw new InvalidOperationException ("The connection is not open.");
  168. if (transaction != null)
  169. throw new InvalidOperationException ("SqlConnection does not support parallel transactions.");
  170. string isolevel = String.Empty;
  171. switch (iso) {
  172. case IsolationLevel.Chaos:
  173. isolevel = "CHAOS";
  174. break;
  175. case IsolationLevel.ReadCommitted:
  176. isolevel = "READ COMMITTED";
  177. break;
  178. case IsolationLevel.ReadUncommitted:
  179. isolevel = "READ UNCOMMITTED";
  180. break;
  181. case IsolationLevel.RepeatableRead:
  182. isolevel = "REPEATABLE READ";
  183. break;
  184. case IsolationLevel.Serializable:
  185. isolevel = "SERIALIZABLE";
  186. break;
  187. }
  188. tds.Execute (String.Format ("SET TRANSACTION ISOLATION LEVEL {0};BEGIN TRANSACTION {1}", isolevel, transactionName));
  189. transaction = new SqlTransaction (this, iso);
  190. return transaction;
  191. }
  192. public void ChangeDatabase (string database)
  193. {
  194. if (!IsValidDatabaseName (database))
  195. throw new ArgumentException (String.Format ("The database name {0} is not valid."));
  196. if (state != ConnectionState.Open)
  197. throw new InvalidOperationException ("The connection is not open.");
  198. tds.Execute (String.Format ("use {0}", database));
  199. }
  200. private void ChangeState (ConnectionState currentState)
  201. {
  202. ConnectionState originalState = state;
  203. state = currentState;
  204. OnStateChange (CreateStateChangeEvent (originalState, currentState));
  205. }
  206. public void Close ()
  207. {
  208. if (transaction != null && transaction.IsOpen)
  209. transaction.Rollback ();
  210. if (dataReader != null || xmlReader != null) {
  211. if(tds != null) tds.SkipToEnd ();
  212. dataReader = null;
  213. xmlReader = null;
  214. }
  215. if (pooling)
  216. if(pool != null) pool.ReleaseConnection (tds);
  217. else
  218. if(tds != null) tds.Disconnect ();
  219. if(tds != null) {
  220. tds.TdsErrorMessage -= new TdsInternalErrorMessageEventHandler (ErrorHandler);
  221. tds.TdsInfoMessage -= new TdsInternalInfoMessageEventHandler (MessageHandler);
  222. }
  223. ChangeState (ConnectionState.Closed);
  224. }
  225. public SqlCommand CreateCommand ()
  226. {
  227. SqlCommand command = new SqlCommand ();
  228. command.Connection = this;
  229. return command;
  230. }
  231. private SqlInfoMessageEventArgs CreateSqlInfoMessageEvent (TdsInternalErrorCollection errors)
  232. {
  233. return new SqlInfoMessageEventArgs (errors);
  234. }
  235. private StateChangeEventArgs CreateStateChangeEvent (ConnectionState originalState, ConnectionState currentState)
  236. {
  237. return new StateChangeEventArgs (originalState, currentState);
  238. }
  239. protected override void Dispose (bool disposing)
  240. {
  241. if (!disposed) {
  242. if (disposing) {
  243. if (State == ConnectionState.Open)
  244. Close ();
  245. parms = null;
  246. dataSource = null;
  247. }
  248. base.Dispose (disposing);
  249. disposed = true;
  250. }
  251. }
  252. [MonoTODO ("Not sure what this means at present.")]
  253. public void EnlistDistributedTransaction (ITransaction transaction)
  254. {
  255. throw new NotImplementedException ();
  256. }
  257. object ICloneable.Clone ()
  258. {
  259. return new SqlConnection (ConnectionString);
  260. }
  261. IDbTransaction IDbConnection.BeginTransaction ()
  262. {
  263. return BeginTransaction ();
  264. }
  265. IDbTransaction IDbConnection.BeginTransaction (IsolationLevel iso)
  266. {
  267. return BeginTransaction (iso);
  268. }
  269. IDbCommand IDbConnection.CreateCommand ()
  270. {
  271. return CreateCommand ();
  272. }
  273. void IDisposable.Dispose ()
  274. {
  275. Dispose (true);
  276. GC.SuppressFinalize (this);
  277. }
  278. public void Open ()
  279. {
  280. string serverName = "";
  281. if (connectionString == null)
  282. throw new InvalidOperationException ("Connection string has not been initialized.");
  283. try {
  284. if (!pooling) {
  285. if(!ParseDataSource (dataSource, out port, out serverName))
  286. throw new SqlException(20, 0, "SQL Server does not exist or access denied.", 17, "ConnectionOpen (Connect()).", dataSource, parms.ApplicationName, 0);
  287. tds = new Tds70 (serverName, port, PacketSize, ConnectionTimeout);
  288. }
  289. else {
  290. pool = (SqlConnectionPool) SqlConnectionPools [connectionString];
  291. if (pool == null) {
  292. if(!ParseDataSource (dataSource, out port, out serverName))
  293. throw new SqlException(20, 0, "SQL Server does not exist or access denied.", 17, "ConnectionOpen (Connect()).", dataSource, parms.ApplicationName, 0);
  294. pool = new SqlConnectionPool (serverName, port, packetSize, ConnectionTimeout, minPoolSize, maxPoolSize);
  295. SqlConnectionPools [connectionString] = pool;
  296. }
  297. tds = pool.AllocateConnection ();
  298. }
  299. }
  300. catch (TdsTimeoutException e) {
  301. throw SqlException.FromTdsInternalException ((TdsInternalException) e);
  302. }
  303. tds.TdsErrorMessage += new TdsInternalErrorMessageEventHandler (ErrorHandler);
  304. tds.TdsInfoMessage += new TdsInternalInfoMessageEventHandler (MessageHandler);
  305. if (!tds.IsConnected)
  306. tds.Connect (parms);
  307. /* Not sure ebout removing these 2 lines.
  308. * The command that gets to the sql server is just
  309. * 'sp_reset_connection' and it fails.
  310. * Either remove them definitely or fix it
  311. else if (connectionReset)
  312. tds.ExecProc ("sp_reset_connection");
  313. */
  314. ChangeState (ConnectionState.Open);
  315. }
  316. private bool ParseDataSource (string theDataSource, out int thePort, out string theServerName)
  317. {
  318. theServerName = "";
  319. string theInstanceName = "";
  320. thePort = 1433; // default TCP port for SQL Server
  321. bool success = true;
  322. int idx = 0;
  323. if ((idx = theDataSource.IndexOf (",")) > -1) {
  324. theServerName = theDataSource.Substring (0, idx);
  325. string p = theDataSource.Substring (idx + 1);
  326. thePort = Int32.Parse (p);
  327. }
  328. else if ((idx = theDataSource.IndexOf ("\\")) > -1) {
  329. theServerName = theDataSource.Substring (0, idx);
  330. theInstanceName = theDataSource.Substring (idx + 1);
  331. // do port discovery via UDP port 1434
  332. port = DiscoverTcpPortViaSqlMonitor (theServerName, theInstanceName);
  333. if (port == -1)
  334. success = false;
  335. }
  336. else {
  337. theServerName = theDataSource;
  338. }
  339. if(theServerName.Equals("(local)"))
  340. theServerName = "localhost";
  341. return success;
  342. }
  343. private int DiscoverTcpPortViaSqlMonitor(string ServerName, string InstanceName)
  344. {
  345. SqlMonitorSocket msock;
  346. msock = new SqlMonitorSocket (ServerName, InstanceName);
  347. int SqlServerPort = msock.DiscoverTcpPort ();
  348. msock = null;
  349. return SqlServerPort;
  350. }
  351. void SetConnectionString (string connectionString)
  352. {
  353. connectionString += ";";
  354. NameValueCollection parameters = new NameValueCollection ();
  355. if (connectionString == String.Empty)
  356. return;
  357. bool inQuote = false;
  358. bool inDQuote = false;
  359. string name = String.Empty;
  360. string value = String.Empty;
  361. StringBuilder sb = new StringBuilder ();
  362. foreach (char c in connectionString)
  363. {
  364. switch (c) {
  365. case '\'':
  366. inQuote = !inQuote;
  367. break;
  368. case '"' :
  369. inDQuote = !inDQuote;
  370. break;
  371. case ';' :
  372. if (!inDQuote && !inQuote) {
  373. if (name != String.Empty && name != null) {
  374. value = sb.ToString ();
  375. parameters [name.ToUpper ().Trim ()] = value.Trim ();
  376. }
  377. name = String.Empty;
  378. value = String.Empty;
  379. sb = new StringBuilder ();
  380. }
  381. else
  382. sb.Append (c);
  383. break;
  384. case '=' :
  385. if (!inDQuote && !inQuote) {
  386. name = sb.ToString ();
  387. sb = new StringBuilder ();
  388. }
  389. else
  390. sb.Append (c);
  391. break;
  392. default:
  393. sb.Append (c);
  394. break;
  395. }
  396. }
  397. if (this.ConnectionString == null)
  398. {
  399. SetDefaultConnectionParameters (parameters);
  400. }
  401. SetProperties (parameters);
  402. this.connectionString = connectionString;
  403. }
  404. void SetDefaultConnectionParameters (NameValueCollection parameters)
  405. {
  406. if (null == parameters.Get ("APPLICATION NAME"))
  407. parameters["APPLICATION NAME"] = "Mono SqlClient Data Provider";
  408. if (null == parameters.Get ("CONNECT TIMEOUT") && null == parameters.Get ("CONNECTION TIMEOUT"))
  409. parameters["CONNECT TIMEOUT"] = "15";
  410. if (null == parameters.Get ("CONNECTION LIFETIME"))
  411. parameters["CONNECTION LIFETIME"] = "0";
  412. if (null == parameters.Get ("CONNECTION RESET"))
  413. parameters["CONNECTION RESET"] = "true";
  414. if (null == parameters.Get ("ENLIST"))
  415. parameters["ENLIST"] = "true";
  416. if (null == parameters.Get ("INTEGRATED SECURITY") && null == parameters.Get ("TRUSTED_CONNECTION"))
  417. parameters["INTEGRATED SECURITY"] = "false";
  418. if (null == parameters.Get ("MAX POOL SIZE"))
  419. parameters["MAX POOL SIZE"] = "100";
  420. if (null == parameters.Get ("MIN POOL SIZE"))
  421. parameters["MIN POOL SIZE"] = "0";
  422. if (null == parameters.Get ("NETWORK LIBRARY") && null == parameters.Get ("NET"))
  423. parameters["NETWORK LIBRARY"] = "dbmssocn";
  424. if (null == parameters.Get ("PACKET SIZE"))
  425. parameters["PACKET SIZE"] = "512";
  426. if (null == parameters.Get ("PERSIST SECURITY INFO"))
  427. parameters["PERSIST SECURITY INFO"] = "false";
  428. if (null == parameters.Get ("POOLING"))
  429. parameters["POOLING"] = "true";
  430. if (null == parameters.Get ("WORKSTATION ID"))
  431. parameters["WORKSTATION ID"] = Dns.GetHostName();
  432. }
  433. private void SetProperties (NameValueCollection parameters)
  434. {
  435. string value;
  436. foreach (string name in parameters) {
  437. value = parameters[name];
  438. switch (name) {
  439. case "APPLICATION NAME" :
  440. parms.ApplicationName = value;
  441. break;
  442. case "ATTACHDBFILENAME" :
  443. case "EXTENDED PROPERTIES" :
  444. case "INITIAL FILE NAME" :
  445. break;
  446. case "CONNECT TIMEOUT" :
  447. case "CONNECTION TIMEOUT" :
  448. connectionTimeout = Int32.Parse (value);
  449. break;
  450. case "CONNECTION LIFETIME" :
  451. break;
  452. case "CONNECTION RESET" :
  453. connectionReset = !(value.ToUpper ().Equals ("FALSE") || value.ToUpper ().Equals ("NO"));
  454. break;
  455. case "CURRENT LANGUAGE" :
  456. parms.Language = value;
  457. break;
  458. case "DATA SOURCE" :
  459. case "SERVER" :
  460. case "ADDRESS" :
  461. case "ADDR" :
  462. case "NETWORK ADDRESS" :
  463. dataSource = value;
  464. break;
  465. case "ENLIST" :
  466. break;
  467. case "INITIAL CATALOG" :
  468. case "DATABASE" :
  469. parms.Database = value;
  470. break;
  471. case "INTEGRATED SECURITY" :
  472. case "TRUSTED_CONNECTION" :
  473. break;
  474. case "MAX POOL SIZE" :
  475. maxPoolSize = Int32.Parse (value);
  476. break;
  477. case "MIN POOL SIZE" :
  478. minPoolSize = Int32.Parse (value);
  479. break;
  480. case "NET" :
  481. case "NETWORK LIBRARY" :
  482. if (!value.ToUpper ().Equals ("DBMSSOCN"))
  483. throw new ArgumentException ("Unsupported network library.");
  484. break;
  485. case "PACKET SIZE" :
  486. packetSize = Int32.Parse (value);
  487. break;
  488. case "PASSWORD" :
  489. case "PWD" :
  490. parms.Password = value;
  491. break;
  492. case "PERSIST SECURITY INFO" :
  493. break;
  494. case "POOLING" :
  495. pooling = !(value.ToUpper ().Equals ("FALSE") || value.ToUpper ().Equals ("NO"));
  496. break;
  497. case "UID" :
  498. case "USER ID" :
  499. parms.User = value;
  500. break;
  501. case "WORKSTATION ID" :
  502. parms.Hostname = value;
  503. break;
  504. }
  505. }
  506. }
  507. static bool IsValidDatabaseName (string database)
  508. {
  509. if (database.Length > 32 || database.Length < 1)
  510. return false;
  511. if (database[0] == '"' && database[database.Length] == '"')
  512. database = database.Substring (1, database.Length - 2);
  513. else if (Char.IsDigit (database[0]))
  514. return false;
  515. if (database[0] == '_')
  516. return false;
  517. foreach (char c in database.Substring (1, database.Length - 1))
  518. if (!Char.IsLetterOrDigit (c) && c != '_')
  519. return false;
  520. return true;
  521. }
  522. private void OnSqlInfoMessage (SqlInfoMessageEventArgs value)
  523. {
  524. if (InfoMessage != null)
  525. InfoMessage (this, value);
  526. }
  527. private void OnStateChange (StateChangeEventArgs value)
  528. {
  529. if (StateChange != null)
  530. StateChange (this, value);
  531. }
  532. private sealed class SqlMonitorSocket : UdpClient
  533. {
  534. // UDP port that the SQL Monitor listens
  535. private static readonly int SqlMonitorUdpPort = 1434;
  536. private static readonly string SqlServerNotExist = "SQL Server does not exist or access denied";
  537. private string server;
  538. private string instance;
  539. internal SqlMonitorSocket (string ServerName, string InstanceName)
  540. : base (ServerName, SqlMonitorUdpPort)
  541. {
  542. server = ServerName;
  543. instance = InstanceName;
  544. }
  545. internal int DiscoverTcpPort ()
  546. {
  547. int SqlServerTcpPort;
  548. Client.Blocking = false;
  549. // send command to UDP 1434 (SQL Monitor) to get
  550. // the TCP port to connect to the MS SQL server
  551. ASCIIEncoding enc = new ASCIIEncoding ();
  552. Byte[] rawrq = new Byte [instance.Length + 1];
  553. rawrq[0] = 4;
  554. enc.GetBytes (instance, 0, instance.Length, rawrq, 1);
  555. int bytes = Send (rawrq, rawrq.Length);
  556. if (!Active)
  557. return -1; // Error
  558. bool result;
  559. result = Client.Poll (100, SelectMode.SelectRead);
  560. if (result == false)
  561. return -1; // Error
  562. if (Client.Available <= 0)
  563. return -1; // Error
  564. IPEndPoint endpoint = new IPEndPoint (Dns.GetHostByName ("localhost").AddressList [0], 0);
  565. Byte [] rawrs;
  566. rawrs = Receive (ref endpoint);
  567. string rs = Encoding.ASCII.GetString (rawrs);
  568. string[] rawtokens = rs.Split (';');
  569. Hashtable data = new Hashtable ();
  570. for (int i = 0; i < rawtokens.Length / 2 && i < 256; i++) {
  571. data [rawtokens [i * 2]] = rawtokens [ i * 2 + 1];
  572. }
  573. if (!data.ContainsKey ("tcp"))
  574. throw new NotImplementedException ("Only TCP/IP is supported.");
  575. SqlServerTcpPort = int.Parse ((string) data ["tcp"]);
  576. Close ();
  577. return SqlServerTcpPort;
  578. }
  579. }
  580. #endregion // Methods
  581. }
  582. }