VB.Net and Database Connections

N

Nick N.

Hi all,

I just started to play around with VB.Net.

I currenlty do Powerbuilder work and was wondering how database connection
management works in VB.net.

My applications typically pop-up a login window, attempts to connect to the
database (Sybase or MSSQL). Once the connection is established, it will open
a MDI Frame and the application will do whatever it is meant to do. (Mostly
reporting by SQL Query...in PB there is something called the Datawindow)

In Powerbuilder, there is a "global" variable called SQLCA which holds the
connection to the database and is accessible from any point in the
application given its global nature.

For instance, to connect to the database, I will set properties for the
SQLCA object then issue the following command:

connect using SQLCA;

then wherever I am in the application, I can reference the SQLCA object for
a valid database connection.

How is something like this done in VB.Net.
I managed to create a login window. I have the connection logic in the
clicked event of the OK button and it does connect to MS SQLServer 2K. Do I
have to then Pass the connection object to the MDI frame and other child
windows etc?

Or is there a cleaner way to do this?
I don't know if declaring a global oledbconnection object is the correct
thing to do.

Please advise!
Thanks
Nick
 
H

Herfried K. Wagner [MVP]

* "Nick N. said:
I currenlty do Powerbuilder work and was wondering how database connection
management works in VB.net.

My applications typically pop-up a login window, attempts to connect to the
database (Sybase or MSSQL). Once the connection is established, it will open
a MDI Frame and the application will do whatever it is meant to do. (Mostly
reporting by SQL Query...in PB there is something called the Datawindow)

This is a VB.NET language group. Notice that you will have a better
chance to get an answer if you post to the ADO.NET newsgroup in future:

<
Web interface:

<http://msdn.microsoft.com/newsgroup...roup=microsoft.public.dotnet.framework.adonet>
 
N

Nick N.

Excuse me there man.
You act like I stepped on dog crap and stepped into your car or something.

S-E-N-S-T-I-V-E

Take it easy will ya?
Take some prozac and call me in the morning.

I heyt 4kin G33ks liek u.
 
T

Tom Leylan

Nick N. said:
I managed to create a login window. I have the connection logic in the
clicked event of the OK button and it does connect to MS SQLServer 2K. Do I
have to then Pass the connection object to the MDI frame and other child
windows etc?

Or is there a cleaner way to do this?
I don't know if declaring a global oledbconnection object is the correct
thing to do.

Hi Nick... First I for one don't think you'd get a better response in
ADO.NET... there would surely be a traffic cop there telling you to post in
dotnet.languages.vb :)

Now... in .Net you typically don't keep the connection open. So you could
can create a connection as you need it or create a class that contains your
connection information. If you make the methods "shared" you don't have to
instantiate an object to reference those methods.

You'll create the connection, open the connection, fetch the data, close the
connection.

Tom
 
C

CJ Taylor

Excuse me there man.
You act like I stepped on dog crap and stepped into your car or something.

S-E-N-S-T-I-V-E

1) There was nothing rude about that comment. You just kinda have to know
herfried, if he says something thats short and to the point, its more than
likely its been answered about 1000 times here and thats pretty much just
cut and copied text (because we've all seen it before)

2) I heyt 4kin G33ks liek u.

No l33t talk in here... 1994 called, they wan't there lingo back...
Take it easy will ya?
Take some prozac and call me in the morning.

I heyt 4kin G33ks liek u.


to
will
open Datawindow)

This is a VB.NET language group. Notice that you will have a better
chance to get an answer if you post to the ADO.NET newsgroup in future:

<
Web interface:
<http://msdn.microsoft.com/newsgroups/default.asp?url=/newsgroups/loadframes
 
N

Nick N.

No, I don't know Herfried, so I did take offense to that...whatever man.
I double posted by mistake (stupid outlook express) and was the first to
point that out.

Nice, real nice...

get some sun once in a while.


CJ Taylor said:
Excuse me there man.
You act like I stepped on dog crap and stepped into your car or something.

S-E-N-S-T-I-V-E

1) There was nothing rude about that comment. You just kinda have to know
herfried, if he says something thats short and to the point, its more than
likely its been answered about 1000 times here and thats pretty much just
cut and copied text (because we've all seen it before)

2) I heyt 4kin G33ks liek u.

No l33t talk in here... 1994 called, they wan't there lingo back...
Take it easy will ya?
Take some prozac and call me in the morning.

I heyt 4kin G33ks liek u.


to will
<http://msdn.microsoft.com/newsgroups/default.asp?url=/newsgroups/loadframes
 
C

Cor

Hi Nick,

Good to see your back, why did you post this also in the Ado.net group? No
friends here? I would normaly not add to Tom Leylan, but because it's you I
do that of course and I can add something.

I know nothing about those databases you told about, but one of the special
thing from Ado.Net is what Tom already told you closing the connections.
Just think on internet when you work with Ado.net than all things become
suddenly clear.

The best way to use that is to get good selected portions of data on the
client using the datasets. Process it there and then send only the changes
back to the server for processing. (A standard feature of the dataset).

But I there are also so called datareaders and datawriters and more of that
stuff with that you keep your connections open. They use the same commands
but not the dataAdapter and the dataset.

And for I forget when you start with datasets, don't forget to look to the
commandbuilder. Most examples from Microsoft are made with SQL while you
normaly only need a good written "Select" statement. The commandbuilder
makes than all the "Update", "Delete" and "Inserts" for you.

Cor
 
C

Chris Dunaway

You'll create the connection, open the connection, fetch the data, close the
connection.

Tom

To add to Tom's answer, ADO.NET pools connections by default so there is
normally no issue with opening a connection and closing it as Tom
suggested. If the connection is opened with the same connection string
within 60 seconds (default) it will just reuse a connnection from the
connection pool.
 
H

Herfried K. Wagner [MVP]

* "Nick N. said:
No, I don't know Herfried, so I did take offense to that...whatever man.
I double posted by mistake (stupid outlook express) and was the first to
point that out.

Nice, real nice...

get some sun once in a while.

Sorry for that... It was not my intention to be rude.
 
N

Nick N.

That's a big relief.
I never intended to offend anyone.
I'm just looking for some honest help from people (like yourself) who can
offer some good advise for the newbie.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top