c# - The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception -


i need solving error.

error {"the type initializer 'system.transactions.diagnostics.diagnostictrace' threw exception."}


using access database , platform build configuration cpu.

sometimes code runs , throws exception. there many similar questions asked here none of them solving error.

this connection string

dbpath = @"d:\ek.mdb"; connectionstring =@"provider=microsoft.jet.oledb.4.0;data source="+dbpath+";user id=admin;password=;"; 

this function open connection
getting error on con.open()

public bool openconnection()         {             if (con == null)             {                 con = new oledbconnection(connectionstring);             }             else if ((con.state == connectionstate.broken || con.state == connectionstate.closed) && (con.state!=connectionstate.open))             {                 con.open();                 tx = con.begintransaction(isolationlevel.readcommitted);                 return true;             }             else if (isconnectionbusy())             {                 throw new dataexception("connection busy");             }             return false;         } 

this how close connection after executing queries

public boolean closeconnection()         {             if(isconnectionbusy())                 throw new dataexception("connection busy");             if (con.state==connectionstate.open)             {                 tx.commit();                 con.close();                 return true;             }             return false;         } public bool isconnectionbusy()     {         switch (con.state)         {             case connectionstate.connecting:             case connectionstate.executing:             case connectionstate.fetching:                 return true;         }         return false;     } 

i cannot find why runs , throws exception.
appreciated. have tried solving error couldn't.

have noticed @ line.

 else if ((con.state == connectionstate.broken || con.state == connectionstate.closed) && (con.state!=connectionstate.open)) 


connection in closed state. when executing con.open() statement connection state changes open , after error thrown.
while debugging error not caused. caused when don't put breakpoint @ place.
@ con.open() when put breakpoint , stop there few seconds first time there no error thrown. after if disable breakpoint , no error thrown...!!!

changed database sqlite , working smoothly...
think in access db there problems transactions.
it got resolved changing database. still not sure causing weird error.


Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -