Skip to content

Commit

Permalink
2005-02-02 Sureshkumar T <tsureshkumar@novell.com>
Browse files Browse the repository at this point in the history
	* SqlConnection.cs: 
	- Database: return db name from database if connection open,
	otherwise take from connection string.
	- Set default values for parameters in the constructor itself.
	- Dangling else problem with Close method.
	- reset values of parms (TdsConnectionParameters) rather setting
	to null.
	- set disposed to false in Open method
	- finally call base.Dispose in Dispose (bool)

	Fixes nunit regressions SqlConnectionTest:DefaultConnectionValues
	and SqlConnectionTest:DatabaseSynonyms.	


svn path=/trunk/mcs/; revision=39974
  • Loading branch information
Sureshkumar T committed Feb 2, 2005
1 parent 7ad878f commit 3361135
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 26 deletions.
15 changes: 15 additions & 0 deletions mcs/class/System.Data/System.Data.SqlClient/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
2005-02-02 Sureshkumar T <tsureshkumar@novell.com>

* SqlConnection.cs:
- Database: return db name from database if connection open,
otherwise take from connection string.
- Set default values for parameters in the constructor itself.
- Dangling else problem with Close method.
- reset values of parms (TdsConnectionParameters) rather setting
to null.
- set disposed to false in Open method
- finally call base.Dispose in Dispose (bool)

Fixes nunit regressions SqlConnectionTest:DefaultConnectionValues
and SqlConnectionTest:DatabaseSynonyms.

2005-01-27 Sureshkumar T <tsureshkumar@novell.com>

* SqlCommand.cs (DeriveParameters): Change parameter name to
Expand Down
81 changes: 55 additions & 26 deletions mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public sealed class SqlConnection : Component, IDbConnection, ICloneable

// Connection parameters
TdsConnectionParameters parms = new TdsConnectionParameters ();
NameValueCollection connStringParameters = null;
bool connectionReset;
bool pooling;
string dataSource;
Expand Down Expand Up @@ -111,7 +112,11 @@ public SqlConnection ()

public SqlConnection (string connectionString)
{
ConnectionString = connectionString;
connectionTimeout = 15; // default timeout
dataSource = ""; // default datasource
packetSize = 8192; // default packetsize

ConnectionString = connectionString;
}

#endregion // Constructors
Expand Down Expand Up @@ -151,7 +156,11 @@ int ConnectionTimeout {
override
#endif // NET_2_0
string Database {
get { return tds.Database; }
get {
if (State == ConnectionState.Open)
return tds.Database;
return GetConnStringKeyValue ("DATABASE", "INITIAL CATALOG");
}
}

internal SqlDataReader DataReader {
Expand Down Expand Up @@ -250,6 +259,20 @@ private void MessageHandler (object sender, TdsInternalInfoMessageEventArgs e)
#endregion // Delegates

#region Methods

internal string GetConnStringKeyValue (params string [] keys)
{
if (connStringParameters == null || connStringParameters.Count == 0)
return "";
foreach (string key in keys) {
string value = connStringParameters [key];
if (value != null)
return value;
}

return "";
}


public new SqlTransaction BeginTransaction ()
{
Expand Down Expand Up @@ -333,10 +356,10 @@ void Close ()
xmlReader = null;
}

if (pooling)
if(pool != null) pool.ReleaseConnection (tds);
else
if(tds != null) tds.Disconnect ();
if (pooling) {
if(pool != null) pool.ReleaseConnection (tds);
}else
if(tds != null) tds.Disconnect ();

if(tds != null) {
tds.TdsErrorMessage -= new TdsInternalErrorMessageEventHandler (ErrorHandler);
Expand Down Expand Up @@ -366,14 +389,19 @@ private StateChangeEventArgs CreateStateChangeEvent (ConnectionState originalSta
protected override void Dispose (bool disposing)
{
if (!disposed) {
if (disposing) {
if (State == ConnectionState.Open)
Close ();
parms = null;
dataSource = null;
}
base.Dispose (disposing);
disposed = true;
try {
if (disposing) {
if (State == ConnectionState.Open)
Close ();
parms.Reset ();
dataSource = ""; // default dataSource
ConnectionString = null;
}
disposed = true;
} finally {
base.Dispose (disposing);
}

}
}

Expand Down Expand Up @@ -463,15 +491,16 @@ void Open ()
else if (connectionReset)
tds.ExecProc ("sp_reset_connection");
*/
disposed = false; // reset this, so using () would call Close ().
ChangeState (ConnectionState.Open);
}

private bool ParseDataSource (string theDataSource, out int thePort, out string theServerName)
{
theServerName = "";
string theInstanceName = "";
if ((theDataSource == null) || (theServerName == null))
if ((theDataSource == null) || (theServerName == null)
|| theDataSource == "")
throw new ArgumentException("Format of initialization string doesnot conform to specifications");

thePort = 1433; // default TCP port for SQL Server
Expand Down Expand Up @@ -552,11 +581,15 @@ private int DiscoverTcpPortViaSqlMonitor(string ServerName, string InstanceName)

void SetConnectionString (string connectionString)
{
NameValueCollection parameters = new NameValueCollection ();

if (( connectionString == null)||( connectionString.Length == 0))
if (( connectionString == null)||( connectionString.Length == 0)) {
this.connectionString = null;
return;
connectionString += ";";
}

NameValueCollection parameters = new NameValueCollection ();
connectionString += ";";

SetDefaultConnectionParameters (parameters);

bool inQuote = false;
bool inDQuote = false;
Expand Down Expand Up @@ -633,15 +666,11 @@ void SetConnectionString (string connectionString)
break;
}
}

if (this.ConnectionString == null)
{
SetDefaultConnectionParameters (parameters);
}


SetProperties (parameters);

this.connectionString = connectionString;
this.connStringParameters = parameters;
}

void SetDefaultConnectionParameters (NameValueCollection parameters)
Expand Down

0 comments on commit 3361135

Please sign in to comment.