2003-02-16 Daniel Morgan <danmorg@sc.rr.com>
authorDaniel Morgan <monodanmorg@yahoo.com>
Sun, 16 Feb 2003 15:13:13 +0000 (15:13 -0000)
committerDaniel Morgan <monodanmorg@yahoo.com>
Sun, 16 Feb 2003 15:13:13 +0000 (15:13 -0000)
* TdsConnection.cs: - parse data source for 2 possible uses:
"Server=hostname",
"Server=hostname,port" and open the connection based on the
resulting server name and port.

svn path=/trunk/mcs/; revision=11626

mcs/class/Mono.Data.TdsClient/ChangeLog
mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient/TdsConnection.cs

index 100c2361637028d3bdca38476560302484841700..1b830d3c0c53a6afbe97b4dcf006c8c63ea77ffc 100644 (file)
@@ -1,3 +1,10 @@
+2003-02-16  Daniel Morgan <danmorg@sc.rr.com>
+
+       * TdsConnection.cs: - parse data source for 2 possible uses:
+       "Server=hostname", 
+       "Server=hostname,port" and open the connection based on the
+       resulting server name and port.  
+
 2002-12-01  Tim Coleman <tim@timcoleman.com>
         * Mono.Data.TdsClient/TdsDataReader.cs:
                 Change to reflect TdsSchemaInfo -> TdsDataColumnCollection
index 66a554dc954a0394f7cccdc6cfe995bc2b624040..544bbd1807b5866e61fe273540eebc2e249f4dfe 100644 (file)
@@ -1,10 +1,12 @@
 //
 // Mono.Data.TdsClient.TdsConnection.cs
 //
-// Author:
+// Authors:
 //   Tim Coleman (tim@timcoleman.com)
+//   Daniel Morgan (danmorg@sc.rr.com)
 //
-// Copyright (C) Tim Coleman, 2002
+// Copyright (C) Tim Coleman, 2002, 2003
+// Copyright (C) Daniel Morgan, 2003
 //
 
 using Mono.Data.Tds.Protocol;
@@ -16,6 +18,7 @@ using System.Data;
 using System.Data.Common;
 using System.EnterpriseServices;
 using System.Net;
+using System.Net.Sockets;
 using System.Text;
 
 namespace Mono.Data.TdsClient {
@@ -282,16 +285,20 @@ namespace Mono.Data.TdsClient {
                [MonoTODO ("Figure out the Tds way to reset the connection.")]
                public void Open () 
                {
+                       string serverName = "";
                        if (connectionString == null)
                                throw new InvalidOperationException ("Connection string has not been initialized.");
 
                        try {
-                               if (!pooling)
-                                       tds = new Tds42 (DataSource, port, PacketSize, ConnectionTimeout);
+                               if (!pooling) {
+                                       ParseDataSource (dataSource, out port, out serverName);
+                                       tds = new Tds42 (serverName, port, PacketSize, ConnectionTimeout);
+                               }
                                else {
                                        pool = (TdsConnectionPool) TdsConnectionPools [connectionString];
                                        if (pool == null) {
-                                               pool = new TdsConnectionPool (dataSource, port, packetSize, ConnectionTimeout, minPoolSize, maxPoolSize);
+                                               ParseDataSource (dataSource, out port, out serverName);
+                                               pool = new TdsConnectionPool (serverName, port, packetSize, ConnectionTimeout, minPoolSize, maxPoolSize);
                                                TdsConnectionPools [connectionString] = pool;
                                        }
                                        tds = pool.AllocateConnection ();
@@ -315,6 +322,22 @@ namespace Mono.Data.TdsClient {
                        }
                }
 
+               private void ParseDataSource (string theDataSource, out int thePort, out string theServerName) 
+               {
+                       theServerName = "";
+                       thePort = 1433; // default TCP port for SQL Server
+                                               \r
+                       int idx = 0;\r
+                       if ((idx = theDataSource.IndexOf (",")) > -1) {\r
+                               theServerName = theDataSource.Substring (0, idx);
+                               string p = theDataSource.Substring (idx + 1);
+                               thePort = Int32.Parse (p);
+                       }
+                       else {
+                               theServerName = theDataSource;
+                       }
+               }
+
                 void SetConnectionString (string connectionString)
                 {
                         connectionString += ";";