[Cleanup] Removed JavaEE csproj and sln files
[mono-project.git] / mcs / class / System.Data / System.Data.SqlClient.jvm / SqlConnection.cs
blobbf556bb0cd9bf48df58ec4ad376f9c01ee502bd6
1 //
2 // System.Data.SqlClient.SqlConnection
3 //
4 // Authors:
5 // Konstantin Triger <kostat@mainsoft.com>
6 // Boris Kirzner <borisk@mainsoft.com>
7 //
8 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
9 //
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:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
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.
32 using System.Data;
33 using System.Data.Common;
34 using System.Collections;
35 using System.Data.ProviderBase;
37 using java.sql;
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
47 #region Fields
49 private const int DEFAULT_PACKET_SIZE = 8192;
51 #endregion // Fields
53 #region Constructors
55 public SqlConnection() : this(null)
59 public SqlConnection(String connectionString) : base(connectionString)
63 #endregion // Constructors
65 #region Events
67 [DataCategory ("InfoMessage")]
68 [DataSysDescription ("Event triggered when messages arrive from the DataSource.")]
69 public event SqlInfoMessageEventHandler InfoMessage;
71 #endregion // Events
73 #region Properties
75 public string WorkstationId
77 get { return (string)ConnectionStringBuilder["workstation id"]; }
80 public int PacketSize
82 get {
83 string packetSize = (string)ConnectionStringBuilder["Packet Size"];
84 if (packetSize == null || packetSize.Length == 0) {
85 return DEFAULT_PACKET_SIZE;
87 try {
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
110 #region Methods
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);
168 #if NET_2_0
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)) {
187 conn.Open ();
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();
200 #region Pooling
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 ();
214 #endregion
215 #region Statistics
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 ();
229 #endregion
230 #endif
231 #endregion // Methods