Click here to Skip to main content
15,906,558 members
Home / Discussions / Database
   

Database

 
GeneralRe: functions Pin
Mazdak27-Aug-04 23:51
Mazdak27-Aug-04 23:51 
GeneralRe: functions Pin
Colin Angus Mackay28-Aug-04 2:04
Colin Angus Mackay28-Aug-04 2:04 
GeneralRe: functions Pin
Mazdak28-Aug-04 3:10
Mazdak28-Aug-04 3:10 
GeneralRe: functions Pin
Colin Angus Mackay28-Aug-04 4:31
Colin Angus Mackay28-Aug-04 4:31 
GeneralRe: functions Pin
Mazdak28-Aug-04 4:40
Mazdak28-Aug-04 4:40 
GeneralRe: functions Pin
Colin Angus Mackay28-Aug-04 2:04
Colin Angus Mackay28-Aug-04 2:04 
GeneralRe: functions Pin
Rocky Moore31-Aug-04 19:55
Rocky Moore31-Aug-04 19:55 
GeneralMdb question Pin
jzb27-Aug-04 23:40
jzb27-Aug-04 23:40 
I use ado.net do something to mdb database. I found out the mdb database's size was been increased when it run some time.I can't confirm what it is cause.
It is my class,

using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;

namespace RoadLib
{
///
/// NdnDataBase の概要の説明です。
///
public class NdnDataBase
{
protected string m_strConnectionString;
private OleDbConnection m_connection = null;
private OleDbTransaction m_transaction = null;

///
/// NdnDataBase の概要説明です
///
public NdnDataBase()
{
//
// TODO: コンストラクタ ロジックをここに追加してください。
//
m_connection = null;
}
///
/// NdnDataBase の概要説明です
///
///
public NdnDataBase(string strConnectionString)
{
m_strConnectionString = strConnectionString;

m_connection = null;
}


///
/// DBコネクションを取得します
///
public OleDbConnection connection
{
get { return m_connection; }
}

///
/// DBトランザクションを取得します
///
public OleDbTransaction transaction
{
get { return m_transaction; }
}

///
/// データベースを開くために使用接続する
///
public string connectionString
{
get { return m_strConnectionString; }

set { m_strConnectionString = value;}
}

///
/// 指定のデータベースでセッションを開く
///
///
public OleDbConnection DBOpen()
{
if(m_connection == null)
{
try
{
//データベース接続パラメータを取得
if (m_strConnectionString == "")
{
return null;
}
m_connection = new OleDbConnection(m_strConnectionString);

//DBオープン
m_connection.Open();
}
catch(Exception err)
{
//NdnPublicFunction.WriteLog(m_strLogFileName, err.Message);
m_connection = null;
throw (err);
}
}

return m_connection;
}

///
/// データベースでセッションを閉じる
///
///
public void DBClose()
{
try
{
//DBクローズ
if (m_connection != null)
{
m_connection.Close();
}
}
catch
{
}
finally
{
//初期値を設定
m_transaction = null;
m_connection = null;
}
}

///
/// SQLステートメントを実行
///
///
///
///
///
public bool ExecSql(string strCommandText, OleDbConnection connection, OleDbTransaction transaction)
{
bool bReturn = false;
OleDbCommand dbCommand = new OleDbCommand(strCommandText, connection, transaction);
try
{
dbCommand.ExecuteNonQuery();
bReturn = true;
}
catch( Exception err)
{
throw (err);
}
return bReturn;
}

///
/// データベースでトランザクションを開始します
///
///
public bool BeginTrans()
{
bool bReturn = false;
try
{
if (m_connection != null)
{
m_transaction = m_connection.BeginTransaction();
bReturn = true;
}
}
catch (Exception err)
{
throw err;
}
return bReturn;
}

///
/// データベースでトランザクションをコミットします
///
///
public bool CommitTrans()
{
bool bReturn = false;
try
{
if (m_transaction != null)
{
m_transaction.Commit();
bReturn = true;
}
}
catch (Exception err)
{
throw err;
}
finally
{
m_transaction = null;
}
return bReturn;
}



///
/// データベースでトランザクションをロールバックします
///
///
public bool RollbackTrans()
{
bool bReturn = false;
try
{
if (m_transaction != null)
{
m_transaction.Rollback();
bReturn = true;
}
}
catch (Exception err)
{
throw err;
}
finally
{
m_transaction = null;
}

return bReturn;
}

}
}


I use it to operate mdb database.
for example:

NdnDataBase database = new NdnDataBase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\nara.mdb;User Id=adminassword=;");
try
{
database.DBOpen();
database.BeginTrans();
database.ExecSql("Delete from ttt");
...
database.ExecSql("Insert into ttt values(1, 2)", database.connection, database.transaction);

database.CommitTrans();
...
}
catch
{
database.RollbackTrans();
}
finally
{
database.DBClose();
}

it operation is in a timer event.

At last when the mdb database's size be to some size, the database is bad.

GeneralRe: Mdb question Pin
Colin Angus Mackay28-Aug-04 2:08
Colin Angus Mackay28-Aug-04 2:08 
Questionado.net connections and .dispose? Pin
Roger Alsing27-Aug-04 1:39
Roger Alsing27-Aug-04 1:39 
AnswerRe: ado.net connections and .dispose? Pin
Colin Angus Mackay28-Aug-04 2:12
Colin Angus Mackay28-Aug-04 2:12 
GeneralRe: ado.net connections and .dispose? Pin
Roger Alsing29-Aug-04 20:25
Roger Alsing29-Aug-04 20:25 
GeneralRe: ado.net connections and .dispose? Pin
Colin Angus Mackay30-Aug-04 1:27
Colin Angus Mackay30-Aug-04 1:27 
AnswerRe: ado.net connections and .dispose? Pin
Rocky Moore31-Aug-04 20:01
Rocky Moore31-Aug-04 20:01 
GeneralIdentity primary key Pin
Diego F.26-Aug-04 23:18
Diego F.26-Aug-04 23:18 
GeneralRe: Identity primary key Pin
David Salter26-Aug-04 23:28
David Salter26-Aug-04 23:28 
GeneralRe: Identity primary key Pin
Diego F.26-Aug-04 23:50
Diego F.26-Aug-04 23:50 
GeneralRe: Identity primary key Pin
David Salter27-Aug-04 1:12
David Salter27-Aug-04 1:12 
GeneralRe: Identity primary key Pin
Colin Angus Mackay27-Aug-04 1:33
Colin Angus Mackay27-Aug-04 1:33 
GeneralSQL and the growing log file Pin
totig25-Aug-04 20:02
totig25-Aug-04 20:02 
GeneralRe: SQL and the growing log file Pin
mikasa26-Aug-04 3:40
mikasa26-Aug-04 3:40 
GeneralRe: SQL and the growing log file Pin
Mekong River26-Aug-04 3:41
Mekong River26-Aug-04 3:41 
GeneralRe: SQL and the growing log file Pin
totig26-Aug-04 3:47
totig26-Aug-04 3:47 
GeneralRe: SQL and the growing log file Pin
Rocky Moore31-Aug-04 20:18
Rocky Moore31-Aug-04 20:18 
GeneralNested Transaction between ADO.NET and T-SQL Pin
Sanjeev Kumar25-Aug-04 14:29
Sanjeev Kumar25-Aug-04 14:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.