dbconnection

C# Retrieving correct DbConnection object by connection string

I have a connection string being passed to a function, and I need to create a DbConnection based object (i.e. SQLConnection, OracleConnection, OLEDbConnection etc) based on this string. Is there any inbuilt functionality to do this, or any 3rd party libraries to assist. We are not necessarily building this connection string, so we cann...

Connecting to DB2 via .NET DbConnection

Our current DB Connection provider model relies on database connectivity to use DbConnection (System.Data) based objects. We can connect to DB2 (*Nix * Windows) via OdbcConnection, but we would like to allow the use of native DB2 Drivers. Is there any way to do so (either .Net framework, OpenSource or (last choice) vendor) without bre...

Properly disposing of a DbConnection

I have a class called DatabaseHelper that wraps a DbConnection. What's the proper way to setup this class for a using statement? I have implemented IDisposible, but I'm not sure when and where I should be calling Connection.Close() or Connection.Dispose(). When I simply call Connection.Dispose() in my own Dispose() method, I'll sometime...

Can a return statement prevent a using statement from closing a connection to a database?

When I'm creating temp tables I get an error message telling me that the temp table already exists. The temp table is unique to the session so it seems my connection isn't closing properly and I think it may have something to do with a return statement I have in my using statement. I have the following code: using (IDbConnection connec...

DbConnection without Db using in-memory DataSet (or similar) as source

I'm trying to unit test a few .NET classes that (for good design reasons) require DbConnections to do their work. For these tests, I have certain data in memory to give as input to these classes. That in-memory data could be easily expressed as a DataTable (or a DataSet that contains that DataTable), but if another class were more appr...

ASP.NET: How to create a connection from a web.config ConnectionString?

How do you construct a DbConnection based on a provider name? Sample provider names System.Data.SqlClient System.Data.OleDb System.Data.Odbc FirebirdSql.Data.FirebirdClient i have connection strings stored in my IIS server's web.config file: <connectionStrings> <add name="development" connectionString="Provider = IBMDA400...

problem with dbConnection, reading in context-params from web.xml

i have some jsp code that reads in Servlet Context parameters from a web.xml file. these parameters hold database connection information so each time the SID or user/password or servername changesm, the programmer doesnt have to go re-code; the user can just change the web.xml file. <context-param> <description>database user name</des...

How to find out all the commands executed on a MySQL database within a given timeframe?

Is it possible to find out all the command executed against a database in a given timeframe? For example, I would like to know who executed insert command on a database table in the last 24 hours. Any help would be greatly appreciated. Thanks. ...

Is java.sql.Connection thread safe?

To rephrase the question: should I avoid sharing instances of classes which implement java.sql.Connection between different threads? ...

Is using a singleton for the connection a good idea in ASP.NET website

Hi everyone, I'm currently using a singleton on my web application so that there is always only one connection to the database. I want to know if it's a good idea because right now I'm having trouble with that error: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred bec...

How much timeout to use in isValid()?

Hi. In the method from Connection, how much timeout should I give it? :S I have no idea what a normal timeout would be, how much time should it take? :) I dont want isValid() to return false if it could return true if it had gotten more time, but also I don't want it to slow down the whole program and give me "freezes". If I set 0, d...

C# + Disposing DbConnection and DbCommand and catching error

Hi, I am trying to understand DbConnection and DbCommand, and the proper way to dispose those objects after use. Following is the code snippet I have. By using "using statement" on DbConnection and DbCommand, would it be sufficient? I am trying to prevent possible memory leak. 2nd question, Do I have to Dispose DbCommand object? t...

ASP.NET Sql Provider

I got a problem. When i'm creating the new project in ASP.NET using VS 2010, it's web.config with a default connection string about SQL Express created. But i haven't even got SQL Express installed. What should i do to change the default AspNetSqlProvider to work with my instance of full-weight SQL Server as a services database? And how ...

Working with database in the OnExecute event (Indy)

Hi , i have a server with these codes : procedure TFrmMain.TCPServerExecute(AContext: TIdContext); begin Res := DoRegister(Name,Family,Username,Password); end; function TFrmMain.DoRegister(Name,Family,Username,Password:string): bool; var Qry: TSQLQuery; begin Qry := TSQLQuery.Create(nil); try Qry.SQLConnection := FrmCon...