stop dbconnection in InitializeComponent()

dotnet framework


  • 1. Closing a notifyicon application
    I have an vb application that is started/stopped using the System.Diagnostics.Process class. The application has both a form, and a notifyicon. (The form is displayed when the user clicks the notifyicon, and hidden when the user minimizes the form) The problem I've run into is that Process class is unable to close the application using either the CloseMainWindow() or Close() method, when the form is hidden. It seems that the form's WndProc() method is not called while it's hidden. I could use the Process's Kill method, but that doesn't allow me to do some cleanup (most notably removing the icon from the tray) Thanks for any suggestions, Tim
  • 2. How check ActiveX already registered from ocx or dll file?
    Hi. Using C#, receiving input ocx or DLL file that has an ActiveX How can verify that has already been registered in the system? tks. Alvaro.
  • 3. DataGridView column DisplayIndex problem
    Hi guys, I try to adjust columns order in DataGridView via DisplayIndex property and it doesn't work me properly. Here is the code: protected override void AdjustGridColumns() { foreach (DataGridViewColumn clmn in _grdCustomizations.Columns) clmn.Visible = false; AdjustColumn("name", "View Customization"); AdjustColumn("userID", "User ID"); AdjustColumn("machineID", "Machine ID"); AdjustColumn("resolutionID", "Resolution ID"); AdjustColumn("createdOn", "Created On"); AdjustColumn("modifiedOn", "Modified On"); } private void AdjustColumn(string name, string displayName){ DataGridViewColumn clmn = _grdCustomizations.Columns[name]; clmn.HeaderText = displayName; clmn.Visible = true; clmn.DisplayIndex = _grdCustomizations.Columns.Count - 1; } After I call AdjustGridColumns method it shows me the next columns order : ID (that shoudn't be at all) View Customization Created On Modified On User ID Machine ID Resolution ID So, what don't I right? Why the "ID" still visible? Why order of columns doesn't right? Thanks a lot
  • 4. strange windows behaviour
    Hi, Before my main form is opened, I have my program check some things. One of the checks will open a form and when the user clicks on a button on that form, it will open another form to fill in some data. On the last form there 2 buttons, one to save and one to cancel. On save the data is stored in properties and then the form is closed, cancel just closes the form. it's something like: sub Main() dim frm as new FirstForm frm.showdialog dim frmMain as new frmMain frmMain.showdialog end sub sub btAdd( sender as object.....) handles dim frmAdd as new SecondForm frmAdd.showdialog strName = etc.. frmadd.dispose end sub on frmAdd the data from the textboxes is put in the properties like Name. The Problem: When either button is pressed, instead of just closing the second form, the first form is also closed and the program continues and loads the main form. So it goes from closing frmAdd straight to 'dim frmMain as new frmMain' in stead of going to frmAdd.dispose and staying in FirstForm. I cannot find anything wrong in my code, but I'm probably overlooking something. Can anyone give me some points on where to look for this kind of problem? thank you, Eric
  • 5. AutoGrow for ListView (View List)
    Heya, I encountered one problem today. I am using ListView for storing some items here. View mode is List (to show as many items as possible), however view is trimmed (instead of TestPackageXXX it will show TestPacka...). Is there any option to change this behavior? Thanks, Martin

stop dbconnection in InitializeComponent()

Postby 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?


Re: stop dbconnection in InitializeComponent()

Postby 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()


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

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

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

I do not want to burden the user with having to pass across some


6. DbConnection Close Throwing Exception

7. DbConnection and Finalizer

8. DbConnection, DbDataReader and DbCommand

Return to dotnet framework


Who is online

Users browsing this forum: No registered users and 26 guest