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); }
protected override string GetConnectionStringWithLoginInfo(string userName, string password) { VistaDBConnectionStringBuilder builder = new VistaDBConnectionStringBuilder(ConnectionString); builder.Password = password; return(builder.ToString()); }
protected override string GetConnectionString() { VistaDBConnectionStringBuilder builder = new VistaDBConnectionStringBuilder(FConnectionString); builder.DataSource = tbDatabase.Text; builder.Password = tbPassword.Text; return(builder.ToString()); }
private void btnAdvanced_Click(object sender, EventArgs e) { using (AdvancedConnectionPropertiesForm form = new AdvancedConnectionPropertiesForm()) { VistaDBConnectionStringBuilder builder = new VistaDBConnectionStringBuilder(ConnectionString); form.AdvancedProperties = builder; if (form.ShowDialog() == DialogResult.OK) { ConnectionString = form.AdvancedProperties.ToString(); } } }
public override string GetConnectionId() { VistaDBConnectionStringBuilder builder = new VistaDBConnectionStringBuilder(ConnectionString); string info = ""; try { info = builder.DataSource; } catch { } return("VistaDB: " + info); }
protected override void SetConnectionString(string value) { FConnectionString = value; VistaDBConnectionStringBuilder builder = new VistaDBConnectionStringBuilder(value); try { tbDatabase.Text = builder.DataSource; } catch { tbDatabase.Text = ""; } try { tbPassword.Text = builder.Password; } catch { tbPassword.Text = ""; } }
private void InitializeDatabase() { string connectionString = ConnectionString; Debug.AssertStringNotEmpty(connectionString); if (File.Exists(_databasePath)) return; // // Make sure that we don't have multiple threads all trying to create the database // lock (_lock) { // // Just double check that no other thread has created the database while // we were waiting for the lock // if (File.Exists(_databasePath)) return; VistaDBConnectionStringBuilder builder = new VistaDBConnectionStringBuilder(connectionString); using (VistaDBConnection connection = new VistaDBConnection()) using (VistaDBCommand command = connection.CreateCommand()) { string passwordClause = string.Empty; if (!string.IsNullOrEmpty(builder.Password)) passwordClause = " PASSWORD '" + EscapeApostrophes(builder.Password) + "',"; // create the database using the webserver's default locale command.CommandText = "CREATE DATABASE '" + EscapeApostrophes(_databasePath) + "'" + passwordClause + ", PAGE SIZE 1, CASE SENSITIVE FALSE;"; command.ExecuteNonQuery(); const string ddlScript = @" CREATE TABLE [ELMAH_Error] ( [ErrorId] INT NOT NULL, [Application] NVARCHAR (60) NOT NULL, [Host] NVARCHAR (50) NOT NULL, [Type] NVARCHAR (100) NOT NULL, [Source] NVARCHAR (60) NOT NULL, [Message] NVARCHAR (500) NOT NULL, [User] NVARCHAR (50) NOT NULL, [StatusCode] INT NOT NULL, [TimeUtc] DATETIME NOT NULL, [AllXml] NTEXT NOT NULL, CONSTRAINT [PK_ELMAH_Error] PRIMARY KEY ([ErrorId]) ) GO ALTER TABLE [ELMAH_Error] ALTER COLUMN [ErrorId] INT NOT NULL IDENTITY (1, 1) GO CREATE INDEX [IX_ELMAH_Error_App_Time_Id] ON [ELMAH_Error] ([TimeUtc] DESC, [ErrorId] DESC)"; foreach (string batch in ScriptToBatches(ddlScript)) { command.CommandText = batch; command.ExecuteNonQuery(); } } } }
/// <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); }
private void InitializeDatabase() { string connectionString = ConnectionString; Debug.AssertStringNotEmpty(connectionString); if (File.Exists(_databasePath)) { return; } // // Make sure that we don't have multiple threads all trying to create the database // lock (_lock) { // // Just double check that no other thread has created the database while // we were waiting for the lock // if (File.Exists(_databasePath)) { return; } VistaDBConnectionStringBuilder builder = new VistaDBConnectionStringBuilder(connectionString); using (VistaDBConnection connection = new VistaDBConnection()) using (VistaDBCommand command = connection.CreateCommand()) { string passwordClause = string.Empty; if (!string.IsNullOrEmpty(builder.Password)) { passwordClause = " PASSWORD '" + EscapeApostrophes(builder.Password) + "',"; } // create the database using the webserver's default locale command.CommandText = "CREATE DATABASE '" + EscapeApostrophes(_databasePath) + "'" + passwordClause + ", PAGE SIZE 1, CASE SENSITIVE FALSE;"; command.ExecuteNonQuery(); const string ddlScript = @" CREATE TABLE [ELMAH_Error] ( [ErrorId] INT NOT NULL, [Application] NVARCHAR (60) NOT NULL, [Host] NVARCHAR (50) NOT NULL, [Type] NVARCHAR (100) NOT NULL, [Source] NVARCHAR (60) NOT NULL, [Message] NVARCHAR (500) NOT NULL, [User] NVARCHAR (50) NOT NULL, [StatusCode] INT NOT NULL, [TimeUtc] DATETIME NOT NULL, [AllXml] NTEXT NOT NULL, CONSTRAINT [PK_ELMAH_Error] PRIMARY KEY ([ErrorId]) ) GO ALTER TABLE [ELMAH_Error] ALTER COLUMN [ErrorId] INT NOT NULL IDENTITY (1, 1) GO CREATE INDEX [IX_ELMAH_Error_App_Time_Id] ON [ELMAH_Error] ([TimeUtc] DESC, [ErrorId] DESC)"; foreach (string batch in ScriptToBatches(ddlScript)) { command.CommandText = batch; command.ExecuteNonQuery(); } } } }
/// <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)); }