2 // System.Data.OleDb.OleDbConnection
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Tim Coleman (tim@timcoleman.com)
8 // Copyright (C) Rodrigo Moya, 2002
9 // Copyright (C) Tim Coleman, 2002
12 using System.ComponentModel;
14 using System.Data.Common;
16 namespace System.Data.OleDb
18 public sealed class OleDbConnection : Component, ICloneable, IDbConnection
22 string connectionString;
23 int connectionTimeout;
30 public OleDbConnection ()
32 libgda.gda_init ("System.Data.OleDb", "1.0", 0, new string [0]);
33 gdaConnection = IntPtr.Zero;
34 connectionTimeout = 15;
35 connectionString = null;
38 public OleDbConnection (string connectionString) : this ()
40 this.connectionString = connectionString;
43 #endregion // Constructors
47 public string ConnectionString {
49 return connectionString;
52 connectionString = value;
56 public int ConnectionTimeout {
58 return connectionTimeout;
62 public string Database {
64 if (gdaConnection != IntPtr.Zero
65 && libgda.gda_connection_is_open (gdaConnection)) {
66 return libgda.gda_connection_get_database (gdaConnection);
73 public string DataSource {
75 if (gdaConnection != IntPtr.Zero
76 && libgda.gda_connection_is_open (gdaConnection)) {
77 return libgda.gda_connection_get_dsn (gdaConnection);
84 public string Provider {
86 if (gdaConnection != IntPtr.Zero
87 && libgda.gda_connection_is_open (gdaConnection)) {
88 return libgda.gda_connection_get_provider (gdaConnection);
95 public string ServerVersion {
97 if (gdaConnection != IntPtr.Zero
98 && libgda.gda_connection_is_open (gdaConnection)) {
99 return libgda.gda_connection_get_server_version (gdaConnection);
106 public ConnectionState State
109 if (gdaConnection != IntPtr.Zero) {
110 if (libgda.gda_connection_is_open (gdaConnection))
111 return ConnectionState.Open;
114 return ConnectionState.Closed;
118 internal IntPtr GdaConnection
121 return gdaConnection;
125 #endregion // Properties
129 public OleDbTransaction BeginTransaction ()
131 if (gdaConnection != IntPtr.Zero)
132 return new OleDbTransaction (this);
137 IDbTransaction IDbConnection.BeginTransaction ()
139 return BeginTransaction ();
142 public OleDbTransaction BeginTransaction (IsolationLevel level)
144 if (gdaConnection != IntPtr.Zero)
145 return new OleDbTransaction (this, level);
150 IDbTransaction IDbConnection.BeginTransaction (IsolationLevel level)
152 return BeginTransaction (level);
155 public void ChangeDatabase (string name)
157 if (gdaConnection == IntPtr.Zero)
158 throw new ArgumentException ();
159 if (State != ConnectionState.Open)
160 throw new InvalidOperationException ();
162 if (!libgda.gda_connection_change_database (gdaConnection, name))
163 throw new OleDbException (this);
168 if (State == ConnectionState.Open) {
169 libgda.gda_connection_close (gdaConnection);
170 gdaConnection = IntPtr.Zero;
174 public OleDbCommand CreateCommand ()
176 if (State == ConnectionState.Open)
177 return new OleDbCommand (null, this);
183 protected override void Dispose (bool disposing)
185 throw new NotImplementedException ();
189 public DataTable GetOleDbSchemaTable (Guid schema, object[] restrictions)
191 throw new NotImplementedException ();
195 object ICloneable.Clone ()
197 throw new NotImplementedException();
200 IDbCommand IDbConnection.CreateCommand ()
202 return CreateCommand ();
207 string provider = "Default";
208 string gdaCncStr = "";
211 char [] separator = { ';' };
213 if (State == ConnectionState.Open)
214 throw new InvalidOperationException ();
216 gdaConnection = libgda.gda_client_open_connection (libgda.GdaClient,
220 /* convert the connection string to its GDA equivalent */
221 //args = connectionString.Split (';');
223 //for (int i = 0; i < len; i++) {
224 // string[] values = args[i].Split (separator, 2);
225 // if (values[0] == "Provider") {
226 // if (values[1] == "SQLOLEDB")
227 // provider = "FreeTDS";
228 // else if (values[1] == "MSDAORA")
229 // provider = "Oracle";
230 // else if (values[2] == "Microsoft.Jet.OLEDB.4.0")
231 // provider = "MS Access";
233 // provider = values[2];
235 // else if (values[0] == "Addr" || values[0] == "Address")
236 // gdaCncStr = String.Concat (gdaCncStr, "HOST=", values[1], ";");
237 // else if (values[0] == "Database")
238 // gdaCncStr = String.Concat (gdaCncStr, "DATABASE=", values[1], ";");
239 // else if (values[0] == "Connection Lifetime")
240 // connectionTimeout = System.Convert.ToInt32 (values[1]);
241 // else if (values[0] == "File Name")
242 // gdaCncStr = String.Concat (gdaCncStr, "FILENAME=", values[1], ";");
243 // else if (values[0] == "Password" || values[0] == "Pwd")
244 // gdaCncStr = String.Concat (gdaCncStr, "PASSWORD=", values[1], ";");
245 // else if (values[0] == "User ID")
246 // gdaCncStr = String.Concat (gdaCncStr, "USERNAME=", values[1], ";");
249 /* open the connection */
250 //System.Console.WriteLine ("Opening connection for provider " +
251 // provider + " with " + gdaCncStr);
252 //gdaConnection = libgda.gda_client_open_connection_from_string (libgda.GdaClient,
258 public static void ReleaseObjectPool ()
260 throw new NotImplementedException ();
265 #region Events and Delegates
267 public event OleDbInfoMessageEventHandler InfoMessage;
268 public event StateChangeEventHandler StateChange;