With C# How to detect that code is exec in IDE of VS 2008 ?

Hi experts!

  Im using C# 2008 , WinForm NET 2. And get this strange behavior:
I have a form  called CommonForm.cs. And have other form, which are inheriting this form, I mean public partial class frmCamp : CommonForm

 I put command to Form Load of CommonForm.cs. Some commands are OK, but when I put one command which open Datareadear from SQL Server I get strange behavior.

 I get error message in Designer when try to show form design of frmCamp which call FormLoad of CommonForm.cs. This is for all form which are based on CommonForm. Message is: Connection property has not been initialized and I can not see design of my form at all.  When I remove code from FormLoad CommonForm.cs which open DataReadear error message disaper.

 Look like Im in desing mode to create forms, but I face with real execution of FormLoad of CommonForm and get this error message bacuse connection is not Open. I open it on other class, when Im in run mode it is OK.

 So question is: how can I detect that my program is under Design mode of IDE of VS2008 and to stop execituon ? I mean somethin like this:

        public static bool bBlockFunction()

            If (bISDesignModeOFIDE) return false;

            string SQL = "SELECT CanLog,GroupCanLog,bEnable,LUpd,Info FROM dbo.qryLogOn WHERE UserID=" + g.UP.UserID ;

            SqlDataReader reader = gDs.GetReader(SQL, g.PR, 0);

            using (reader)
                    if (!g.bVar(reader["CanLog"]) )
                    { g.Msg("You personal account  i



Or - second option - how to tell to IDE that this is nor citical error and to show me design of form ??? In general problem is that I can not see design of my form after this error message.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you can use this.DesignMode

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You can use the following:

if(this.DesignMode) {    // inside design mode}
it will work in a user control and inside a form.
ha able - beat you to it this time :)
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

You could try testing if you are in Debug mode or not.

Note that you will need to your EXE to be a Release version.

    Console.WriteLine("Debug version");

Open in new window

> second option - how to tell to IDE that this is nor citical error and to show me design of form ???

you can always put in a try/catch and just continue. Put the expected error in the catch clause. However, be aware that you will also catch a legitimate error in runtime, so I would not recommend that approach.
> ha able - beat you to it this time :)
haha, indeed ;-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.