getting an error when switching between programs and when running exe

hello experts whenever i switch to another program window then return to the project i get this error
or if i try to execute the .exe file  

An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll

Additional information: Object reference not set to an instance of an object.

the debugger then points to the first line

Public Class Form1

of my project.

i doublechecked that form1 is set as the default form    

any ideas on what could cause this?  
thanks in advance
LVL 1
apumaAsked:
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.

apumaAuthor Commented:
I did some more research and it looks like i am getting this error due to a SQL connection.
i started a blank project and connected to the same database    and i get simmilar errors.

Is there a special step i need to go through to connect to a sql DB on a server   besides using the server explorer and generating a dataset?
DotNetLover_BaanCommented:
Are you doing anything in LostFocus or Deactivated events of your form?

-Baan
apumaAuthor Commented:
no   I can just have a blank form with only the connection set-up and i will get this error.

Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

DotNetLover_BaanCommented:
sounds interesting. Lets see where and how you are making the connection.
-Baan
apumaAuthor Commented:
i am connecting using the server explorer, which creates a sqlconnection and a sqldataadapter object in the "bin" under the design form.


if i run the project from VS it runs fine   selects and saves data with no issue.   just when i switch to another screen   then switch back.


DotNetLover_BaanCommented:
Personally I like to make connections to the database from my code. (wizards scare me.......:() ) That in turn gives you more control on things specially when things go wrong. Moreover its easy to debug. If you want to switch to coding method, I would love to help you whenever you need it.

In your case, hmm...., how about reinstalling framework? (again I am not sure).

-Baan
apumaAuthor Commented:
I agree with your point about the wizards.   not the biggest fan either.   im fairly new at vb.net so i would probbably need some help figuring out how to databind in code.  im guessing it's fairly easy to just copy what the windows generated stuff does.  ill give that a shot and see what i come up with
apumaAuthor Commented:
So i did some more testing and i tried starting a new project in "my vasual studios projects" folder with nothing on it at all    no connections  no anything,  and i get that problem.   so it is not the sql connection causing it.     if  i run a project from my flash drive it runs perfectly. any ideas?  could this be a .net framework issue?
DotNetLover_BaanCommented:
Quite possible. Try installing Framework SDK.
http://msdn.microsoft.com/netframework/downloads/framework1_1/

-Baan
DotNetLover_BaanCommented:
One more thing .. how much free disk space and RAM do you have?

-Baan
apumaAuthor Commented:
46 gigs of free space and 512mb ram

i moved the project on to my flash drive and it runs fine from there on the same machine,   also works fine on other machines from the .exe
apumaAuthor Commented:
if i copy the .exe from the flash drive to the c drive that also executes without issue.  
DotNetLover_BaanCommented:
It means that your framework is working just fine. Only when you run something in DEBUG mode with VB.Net it's not working. Chances are your VS.Net is not installed properly. What do you think?

-Baan
apumaAuthor Commented:
why would it work if the project was sitting on a flash drive   and not when it is on the c drive?

the only thing i can think is that maybe there is a conflict with the NTFS where as i beleive the flash storage is FAT
DotNetLover_BaanCommented:
But when you run the exe from your hard disk it's working fine.. right?
apumaAuthor Commented:
yes,  i think the problem uccors during compilation, when on my c drive.
DotNetLover_BaanCommented:
right... thats why I am guessing that the problem might be with the VS.Net installation.

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
apumaAuthor Commented:
re-installing from our disk is not an option as the disk is scratched.
so i may just be SOL
that or the flash drive becomes a permanent fixture to the machine
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
Visual Basic.NET

From novice to tech pro — start learning today.