Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Please see my code below..
string DSource = Path.Combine(CommonItems.DatabaseLocation, lb_project.SelectedItem.ToString() + ".mdb");
string Connection_String = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=1234;" + "Data Source=" + DSource + ";";

ADOX._Catalog cat = new ADOX.Catalog();
cat.Create(Connection_String);

Catalog catalog = new Catalog();
Connection connection = new Connection();
connection.Open(Connection_String, null, null, 0);
catalog.ActiveConnection = connection;

Table seq_table = new Table();
seq_table.Name = "seq_data";
catalog.Tables.Append(seq_table);

seq_table.Columns.Append("seq", ADOX.DataTypeEnum.adVarWChar, 20);
seq_table.Columns.Append("rev", ADOX.DataTypeEnum.adVarWChar, 100);

connection.Close();


After creating the database I am closing the connection, even though the ldb file is still existing until I exit the application.
what is the wrong with my code?.I know ldb is not a dangerous one, but I need to avoid unnecessary connections. Please help me on this..
Posted

1 solution

You are actually open the connection twice ,but closing once - the second one will be closed only after your application exits...
First:
C#
cat.Create(Connection_String);

Second:
C#
connection.Open(Connection_String, null, null, 0);

Looking at your code, the first can be removed and you still get the same...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900