Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

database connection problems

Status
Not open for further replies.

trimakassi

Programmer
Aug 5, 2005
20
MA
my application was working perfectly well before i tried to refine it. I have an mdi form and 3 other forms. Before the problem, for every form i had a new connection to my database with the required adapters.

To make my application more effecient I thought of making one connection and connect all the needed adapters fro the mdi form then call the adapters from the different forms.
ex:

the following are set in main_menu

connection1
OledbDataadapter1
OledbDataadapter2
dsEmployee


Module

public module
public adapters as Main_menu
end class

now everytime i try filling a dataset from any form i use

adapters.Oledataadapter1.fill(dsEmployee)

this however seem not to be the correct i keep getting :

"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."

trimakassi
 
perhaps try giving us some more real code you use.

And I don't think your improvemnts are for the better. Try stepping away from modules and try using shared thigies or make singleton classes. Using more connections isn't really a bad thing. You should just make sure your connections open and close as fast as possible.

BTW .net does it's own connectionpooling and will keep connections open like it thinks is best for you.

Christiaan Baes
Belgium

"My new site" - Me
 
i am new to programing,

how can I use shared thigies or singleton classes

trimakasssi
 
If you declare a variable shared then you don't need an instance of that class just like a module

For example

Code:
public class thingie
  private shared s as string = "blah"

  public shared function gets() as string
    return s
  end sub
end class

and then you can do this in your code
Code:
dim p as string = thignie.gets

without doing a dim new thingie.

singleton classes are a bit more difficult to explain. But lets just say that they make sure that you can only have one instance of a certain class. For example I want a search form that can only be opened once and is the same for every other form calling it.

Code:
public class thingie
  private shared instance as thingie
  private sub New()
    'constructor
  end sub

  private function getInstance() as thingie
    if instance is nothing then
      instance = new thingie()
    end if
    return instance
  end function
end class

notice how the constructor is now private so

dim d as new thingie() is no longer possible

the only way to get an instance of a class
is by doing this.

dim d as thingie = thingie.getInstance()

This concludes this lesson for today.

Christiaan Baes
Belgium

"My new site" - Me
 
Chrissie
For tomorrows lesson, can we have both thingies, and watchamacallits. Maybe even throw in an oojamawotsit for good measure.


Sweep
...if it works, you know the rest..
Always remember that Google is your friend

curse.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top