/// <summary> /// Attaches an existing database at the specified location /// </summary> /// <param name="databaseName">The file name (relative or absolute) at which the database will be attached</param> /// <remarks> /// Attaching a database to the instance enables that database to be /// opened for access. When a database is attached, its file is /// opened and so must be available to be locked as required. The /// file will be held open until the database is detached or until the /// instance is disposed. /// </remarks> public void AttachDatabase(string databaseName) { lock (this) { this.CheckDisposed(); AttachDatabaseGrbit grbit = AttachDatabaseGrbit.None; if (this.isamInstance.ReadOnly) { grbit |= AttachDatabaseGrbit.ReadOnly; } Api.JetAttachDatabase(this.Sesid, databaseName, grbit); } }
/// <summary> /// Determines if there is a database at the specified location /// </summary> /// <param name="databaseName">The file name (relative or absolute) at which the database may exist</param> /// <returns>true if the database exists and is a valid database file, false otherwise</returns> public bool Exists(string databaseName) { lock (this) { this.CheckDisposed(); try { AttachDatabaseGrbit grbit = AttachDatabaseGrbit.None; if (this.isamInstance.ReadOnly) { grbit |= AttachDatabaseGrbit.ReadOnly; } Api.JetAttachDatabase(this.Sesid, databaseName, grbit); try { Api.JetDetachDatabase(this.Sesid, databaseName); } catch (EsentDatabaseInUseException) { } return(true); } catch (EsentFileNotFoundException) { return(false); } catch (EsentDatabaseInvalidPathException) { return(false); } catch (EsentErrorException) { return(true); } } }
/// <summary> /// Attaches a database file for use with a database instance. In order to use the /// database, it will need to be subsequently opened with <see cref="JetOpenDatabase"/>. /// </summary> /// <param name="sesid">The session to use.</param> /// <param name="database">The database to attach.</param> /// <param name="maxPages"> /// The maximum size, in database pages, of the database. Passing 0 means there is /// no enforced maximum. /// </param> /// <param name="grbit">Attach options.</param> /// <returns>An ESENT warning code.</returns> public static JET_wrn JetAttachDatabase2(JET_SESID sesid, string database, int maxPages, AttachDatabaseGrbit grbit) { return Api.Check(Impl.JetAttachDatabase2(sesid, database, maxPages, grbit)); }
/// <summary> /// Attaches a database file for use with a database instance. In order to use the /// database, it will need to be subsequently opened with <see cref="JetOpenDatabase"/>. /// </summary> /// <param name="sesid">The session to use.</param> /// <param name="database">The database to attach.</param> /// <param name="grbit">Attach options.</param> /// <returns>An ESENT warning code.</returns> public static JET_wrn JetAttachDatabase(JET_SESID sesid, string database, AttachDatabaseGrbit grbit) { return Api.Check(Impl.JetAttachDatabase(sesid, database, grbit)); }
public void AttachDatabase(AttachDatabaseGrbit grbit) { Api.JetAttachDatabase(_session, Database.DatabasePath, grbit); }