stop dbconnection in InitializeComponent()
by jarb » Fri, 27 Oct 2006 11:00:13 GMT
Is there any way to change the order code is generated in InitializeComponent()?
Or to keep designer generated ADO.NET code from trying to connect?
If im dropping data adapters, connections, etc.. in the designer, as soon as the
connection string is set any following code that references the connection
object initiates the connection. I dont want any connection happening until I
ask for it with a Fill() call. I dont want to have to wrap all my constructors
with database exception handlers. Surely there is a way of having some control
over this?
thanks
Re: stop dbconnection in InitializeComponent()
by jarb » Wed, 01 Nov 2006 09:31:13 GMT
No response on this one. I guess the only way to stop the connection attempts is
to manually edit the designer generated code. Make the connection string = line
be the last line in the function. Unfortunately you have to do this after every
time you open the component in designer because it moves the code around again.
Similar Threads:
1.Does DbConnection.Dispose() call Close()?
2.ADO.Net DBConnection Visualizer
3.Trouble with DbConnection.GetSchema()
Hello,
I trying to get some schema info with help of string of code:
_conn.GetSchema("Tables", sa)
where _conn is type of DbConnection. So - sa must be string[] type. If
I define sa like this:
string[] sa = new string[3];
sa[0] = "master";
sa[1] = null;
sa[2] = "users";
all fine, I get row "master dbo users BASE TABLE". This was SYSTEM
database. Now want the same but for my own MSSQL database with name
"TestBase". Such database definitely exist on the same server and
definitely has table "MyTbl2". So I re-define sa:
string[] sa = new string[3];
sa[0] = "TestBase";
sa[1] = null;
sa[2] = "MyTbl2";
and get... nothing. Just empty DataTable? :( What's wrong?
4.How to determine the data-provider type from a DbConnection ob
If you use ODBC is simple using reflection
Something in the line of this
IDbConnection DBConnection4Try= (IDbConnection) DBGenericConnection;
DBConnection4Try.ConnectionString=SN=bla bla
DBConnection4Try.Open();
Type ConnectionType =DBConnection4Try.GetType();
PropertyInfo DriverPropertyInfo = ConnectionType.GetProperty("Driver");
string Driver = (string) DriverPropertyInfo.GetValue(DBConnection4Try, null);
If Driver is "SQLSRV32.DLL" then the connection is to a SQL Server.
If is SORCL32.DLLthen the connection is to Oracle.
Piece of cake!
The generic connection object works as the same...
Be careful though when closing commands object and reader the close and
explicit dispose order must be respected on ODBC. Otherwise it could happen
that you are able to execute once and next time you could get errors.
"Herby" wrote:
>
> Thanks for that, thats given me an idea, i could use reflection too.>
> >
>
5.How to determine the data-provider type from a DbConnection object
Im trying to use prepared SQL and need to support both Oracle and SQL
server. Im only dealing with the abstraction - i.e. DbConnection
object.
When using DbParameters, for Oracle i have to use :myVar but for SQL
Server i have to use @myVar. So the abstraction breaks down here.
Consequently i need to ask "What database server are you?" to then
prefix the correct parameter marker character( bring back the ? ).
Iv checked the DbConnection object and there do not seem to be any
appropriate methods, whereby the provider can override some method
which will return the identity.
How best can i determine the type of the DBMS i am currently connected
too?
I do not want to burden the user with having to pass across some
identity...
Thanks.
6. DbConnection Close Throwing Exception
7. DbConnection and Finalizer
8. DbConnection, DbDataReader and DbCommand