2 // System.Data.SqlClient.SqlConnection
5 // Konstantin Triger <kostat@mainsoft.com>
6 // Boris Kirzner <borisk@mainsoft.com>
8 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Data.Common;
34 using System.Collections;
35 using System.Data.ProviderBase;
39 using System.Configuration;
40 using Mainsoft.Data.Configuration;
41 using Mainsoft.Data.Jdbc.Providers;
43 namespace System.Data.SqlClient
45 public class SqlConnection : AbstractDBConnection
49 private const int DEFAULT_PACKET_SIZE = 8192;
55 public SqlConnection() : this(null)
59 public SqlConnection(String connectionString) : base(connectionString)
63 #endregion // Constructors
67 [DataCategory ("InfoMessage")]
68 [DataSysDescription ("Event triggered when messages arrive from the DataSource.")]
69 public event SqlInfoMessageEventHandler InfoMessage;
75 public string WorkstationId
77 get { return (string)ConnectionStringBuilder["workstation id"]; }
83 string packetSize = (string)ConnectionStringBuilder["Packet Size"];
84 if (packetSize == null || packetSize.Length == 0) {
85 return DEFAULT_PACKET_SIZE;
88 return Convert.ToInt32(packetSize);
90 catch(FormatException e) {
91 throw ExceptionHelper.InvalidValueForKey("packet size");
93 catch (OverflowException e) {
94 throw ExceptionHelper.InvalidValueForKey("packet size");
99 protected override IConnectionProvider GetConnectionProvider() {
100 IDictionary conProviderDict = ConnectionStringDictionary.Parse(ConnectionString);
101 string provider = (string)conProviderDict["Provider"];
102 if (provider == null)
103 provider = "SQLCLIENT";
105 return GetConnectionProvider("Mainsoft.Data.Configuration/SqlClientProviders", provider);
108 #endregion // Properties
112 protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel) {
113 return BeginTransaction(isolationLevel);
116 public SqlTransaction BeginTransaction(String transactionName)
118 return BeginTransaction(IsolationLevel.ReadCommitted,transactionName);
121 public new SqlTransaction BeginTransaction(IsolationLevel isolationLevel)
123 return BeginTransaction(isolationLevel,"Transaction");
126 public new SqlTransaction BeginTransaction()
128 return BeginTransaction(IsolationLevel.ReadCommitted);
131 public SqlTransaction BeginTransaction(IsolationLevel isolationLevel, string transactionName)
133 return new SqlTransaction(isolationLevel, this, transactionName);
136 public new SqlCommand CreateCommand()
138 return new SqlCommand(this);
141 protected override DbCommand CreateDbCommand() {
142 return CreateCommand();
145 protected internal sealed override void OnSqlWarning(SQLWarning warning)
147 SqlErrorCollection col = new SqlErrorCollection(warning, this);
148 OnSqlInfoMessage(new SqlInfoMessageEventArgs(col));
151 protected sealed override SystemException CreateException(SQLException e)
153 return new SqlException(e, this);
156 protected sealed override SystemException CreateException(string message)
158 return new SqlException(message, null, this);
161 private void OnSqlInfoMessage (SqlInfoMessageEventArgs value)
163 if (InfoMessage != null) {
164 InfoMessage (this, value);
170 [MonoNotSupported("")]
171 public static void ChangePassword (string connectionString, string newPassword)
173 throw new NotImplementedException ();
175 // FIXME: refactored from Mono implementation. Not finished!!!
176 if (connectionString == null || newPassword == null || newPassword == String.Empty)
177 throw new ArgumentNullException ();
178 if (newPassword.Length > 128)
179 throw new ArgumentException ("The value of newPassword exceeds its permittable length which is 128");
181 SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder (connectionString);
182 if (builder.IntegratedSecurity) {
183 throw new ArgumentException ("Can't use integrated security when changing password");
186 using (SqlConnection conn = new SqlConnection (connectionString)) {
188 SqlCommand cmd = conn.CreateCommand ();
189 cmd.CommandText = "sp_password";
190 cmd.CommandType = CommandType.StoredProcedure;
191 // FIXME: Need to extract old password and user from our structures
192 // of the connectionString.
193 cmd.Parameters.Add (builder.Password); // Is this good???
194 cmd.Parameters.Add (newPassword);
195 cmd.Parameters.Add (builder.UserID); // Is this good???
196 cmd.ExecuteNonQuery();
202 [MonoNotSupported("Pooling not supported")]
203 public static void ClearPool (SqlConnection connection)
205 throw new NotImplementedException ();
208 [MonoNotSupported ("Pooling not supported")]
209 public static void ClearAllPools ()
211 throw new NotImplementedException ();
217 [MonoNotSupported ("Statistics not supported")]
218 public IDictionary RetrieveStatistics ()
220 throw new NotImplementedException ();
223 [MonoNotSupported ("Statistics not supported")]
224 public void ResetStatistics ()
226 throw new NotImplementedException ();
231 #endregion // Methods