private IVistaDBDatabase GetDatabase(string connectionString) { var builder = new VistaDBConnectionStringBuilder(connectionString); IVistaDBDatabase database = _dda.OpenDatabase(builder.DataSource, builder.OpenMode, builder.Password); return(database); }
private IVistaDBDatabase GetDatabase(string connectionString) { var builder = new VistaDBConnectionStringBuilder(connectionString); var password = !String.IsNullOrWhiteSpace(builder.Password) ? builder.Password : null; IVistaDBDatabase database = _dda.OpenDatabase(builder.DataSource, builder.OpenMode, password); return(database); }
public DataTable GetDatabases() { DataTable metaData = new DataTable(); metaData.Columns.Add("CATALOG_NAME", Type.GetType("System.String")); metaData.Columns.Add("DESCRIPTION", Type.GetType("System.String")); metaData.Columns.Add("SCHEMA_NAME", Type.GetType("System.String")); metaData.Columns.Add("SCHEMA_OWNER", Type.GetType("System.String")); metaData.Columns.Add("DEFAULT_CHARACTER_SET_CATALOG", Type.GetType("System.String")); metaData.Columns.Add("DEFAULT_CHARACTER_SET_SCHEMA", Type.GetType("System.String")); metaData.Columns.Add("DEFAULT_CHARACTER_SET_NAME", Type.GetType("System.String")); DataRow row = metaData.NewRow(); metaData.Rows.Add(row); IVistaDBDatabase db = DDA.OpenDatabase(dbName, VistaDBDatabaseOpenMode.NonexclusiveReadOnly, password); row["CATALOG_NAME"] = GetDatabaseName(); row["DESCRIPTION"] = db.Description; return(metaData); }
/// <summary> /// Turns off auto record identity generation so the record id from the master database can be used. /// </summary> /// <param name="tableName">SQL table name</param> /// <param name="columnName">the identity column</param> /// <param name="enable"></param> public void SetIdentityInsert(string tableName, string columnName, bool enable) { // VistaDB DDA code IVistaDBTable tbl = null; try { IVistaDBDDA DDAObj = VistaDBEngine.Connections.OpenDDA(); string vistaDbPath = (string)AppDomain.CurrentDomain.GetData("DataDirectory"); Debug.WriteLine("FormsSql.SetIdentityInsert VistaDbPath: " + vistaDbPath); // IVistaDBDatabase db = DDAObj.OpenDatabase(System.AppDomain.CurrentDomain.BaseDirectory + "App_Data\\forms.vdb5", VistaDB.VistaDBDatabaseOpenMode.NonexclusiveReadWrite, "aj80995"); IVistaDBDatabase db = DDAObj.OpenDatabase(vistaDbPath + @"\forms.vdb5", VistaDB.VistaDBDatabaseOpenMode.NonexclusiveReadWrite, "P@ssword1"); tbl = db.OpenTable(tableName, false, false); } catch (Exception xcptn) { Debug.WriteLine("FormsSql.SetIdentityInsert Exception: " + xcptn.Message); throw xcptn; } // table1s.AddColumn("ID", VistaDBType.Int); // table1s.DefineColumnAttributes("ID", false, false, false, false, null, null); // table1s.AddColumn("COLINT", VistaDBType.Int); // table1s.DefineColumnAttributes("COLINT", false, false, false, false, null, null); if (tbl.EnforceIdentities) { if (enable) { tbl.DropIdentity(columnName); } else { if (tableName == "def_FormResults") { int min = getMin(columnName, tableName); int next = min - 1; tbl.CreateIdentity(columnName, next.ToString(), "-1"); } else { int max = getMax(columnName, tableName); int next = max + 1; tbl.CreateIdentity(columnName, next.ToString(), "1"); } } } else { if (!enable) { if (tableName == "def_FormResults") { int min = getMin(columnName, tableName); int next = min - 1; tbl.CreateIdentity(columnName, next.ToString(), "-1"); } else { int max = getMax(columnName, tableName); int next = max + 1; tbl.CreateIdentity(columnName, next.ToString(), "1"); } } } // tbl.CreateIndex("Primary", "ID", true, true); // tbl.CreateIndex("idxDate", "COLDATETIME", false, false); tbl.Close(); tbl.Dispose(); tbl = null; }
public void OpenDatabase(bool readOnly) { System.Diagnostics.Debug.Assert(dda == null, "The database is already open"); dda = VistaDBEngine.Connections.OpenDDA(); db = dda.OpenDatabase(Path.Combine(basePath, "game.vdb3"), readOnly ? VistaDBDatabaseOpenMode.NonexclusiveReadOnly : VistaDBDatabaseOpenMode.ExclusiveReadWrite, null); packTable = db.OpenTable("Pack", false, readOnly); markerTable = db.OpenTable("Marker", false, readOnly); cardTable = db.OpenTable("Card", false, readOnly); cardModelCache = new Dictionary<Guid, CardModel>(); setCache = new Dictionary<Guid, Set>(); }
public void GetDBCompexInfo(string dbName) { try { using (IVistaDBDDA conn = VistaDBEngine.Connections.OpenDDA()) { using (IVistaDBDatabase db = conn.OpenDatabase(dbName, VistaDBDatabaseOpenMode.ExclusiveReadOnly, null)) { Console.WriteLine("METAINFORMATION FOR " + dbName + " DATABASE"); Console.WriteLine("-------------------------------------------"); Console.WriteLine("Table Description: " + db.Description); Console.WriteLine("Row count: " + db.RowCount.ToString()); Console.WriteLine("PageSize: " + db.PageSize.ToString()); Console.WriteLine("Open mode: " + db.Mode.ToString()); Console.WriteLine("Culture: " + db.Culture.ToString()); Console.WriteLine("Case Sensitive: " + db.CaseSensitive.ToString()); ArrayList tables = db.EnumTables(); foreach (string table in tables) { IVistaDBTableStructure tblStructure = db.TableStructure(table); Console.WriteLine("============================================"); Console.WriteLine("Table " + table); Console.WriteLine("============================================"); //columns Console.WriteLine("COLUMNS:"); foreach (IVistaDBColumnAttributes colInfo in tblStructure) { Console.WriteLine("\t" + colInfo.Name); //use colInfo for getting columns metadata } //indexes Console.WriteLine("INDEXES:"); foreach (IVistaDBIndexInformation indexInfo in tblStructure.Indexes) { Console.WriteLine("\t" + indexInfo.Name); //use indexInfo for getting columns metadata } //constraints Console.WriteLine("CONSTRAINTS:"); foreach (IVistaDBConstraintInformation constrInfo in tblStructure.Constraints) { Console.WriteLine("\t" + constrInfo.Name); //use constrInfo for getting columns metadata } //foreignKeys Console.WriteLine("FOREIGN KEYS:"); foreach (IVistaDBRelationshipInformation relInfo in tblStructure.ForeignKeys) { Console.WriteLine("\t" + relInfo.Name); //use foreignKeys for getting columns metadata } } } } } catch (VistaDBException ex) { } catch { } }
/// <summary> /// Returns a page of errors from the databse in descending order /// of logged time. /// </summary> public override int GetErrors(int pageIndex, int pageSize, IList errorEntryList) { if (pageIndex < 0) { throw new ArgumentOutOfRangeException("pageIndex", pageIndex, null); } if (pageSize < 0) { throw new ArgumentOutOfRangeException("pageSize", pageSize, null); } VistaDBConnectionStringBuilder builder = new VistaDBConnectionStringBuilder(_connectionString); // Use the VistaDB Direct Data Access objects IVistaDBDDA ddaObjects = VistaDBEngine.Connections.OpenDDA(); // Create a connection object to a VistaDB database IVistaDBDatabase vistaDB = ddaObjects.OpenDatabase(_databasePath, builder.OpenMode, builder.Password); // Open the table IVistaDBTable elmahTable = vistaDB.OpenTable("ELMAH_Error", false, true); elmahTable.ActiveIndex = "IX_ELMAH_Error_App_Time_Id"; if (errorEntryList != null) { if (!elmahTable.EndOfTable) { // move to the correct record elmahTable.First(); elmahTable.MoveBy(pageIndex * pageSize); int rowsProcessed = 0; // Traverse the table to get the records we want while (!elmahTable.EndOfTable && rowsProcessed < pageSize) { rowsProcessed++; string id = Convert.ToString(elmahTable.Get("ErrorId").Value, CultureInfo.InvariantCulture); Error error = new Error(); error.ApplicationName = (string)elmahTable.Get("Application").Value; error.HostName = (string)elmahTable.Get("Host").Value; error.Type = (string)elmahTable.Get("Type").Value; error.Source = (string)elmahTable.Get("Source").Value; error.Message = (string)elmahTable.Get("Message").Value; error.User = (string)elmahTable.Get("User").Value; error.StatusCode = (int)elmahTable.Get("StatusCode").Value; error.Time = ((DateTime)elmahTable.Get("TimeUtc").Value).ToLocalTime(); errorEntryList.Add(new ErrorLogEntry(this, id, error)); // move to the next record elmahTable.Next(); } } } return(Convert.ToInt32(elmahTable.RowCount)); }