473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

is it a good idea to use SQL connection?

Hi,

(newbie in C#) is it a good idea to use SQL Connection, SQL Data Adapter,...
in C#? when I am design a form, I can use SQL Connection and set the
properties to connect to a database. I guess after unloading the form, this
connection will be closed. but as I know, it's better to open a connection
when we need it and after using, we should close it. I can do it without
using SQL Connection component (by using SqlConnection class). now which one
is better? using SQL Connection is very easy but I'd like to have the best
performance.

thanks,
Mojtaba
Nov 16 '05 #1
5 1594
Hi Mojtaba,

In designer you only design the connection - it won't open it for you thus
it won't make much difference.
Though I preffer to create it by code right before I need it and dispose it
as soon as possible.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Mojtaba Faridzad" <mf*******@hotmail.com> wrote in message
news:Oc**************@TK2MSFTNGP15.phx.gbl...
Hi,

(newbie in C#) is it a good idea to use SQL Connection, SQL Data
Adapter,... in C#? when I am design a form, I can use SQL Connection and
set the properties to connect to a database. I guess after unloading the
form, this connection will be closed. but as I know, it's better to open a
connection when we need it and after using, we should close it. I can do
it without using SQL Connection component (by using SqlConnection class).
now which one is better? using SQL Connection is very easy but I'd like to
have the best performance.

thanks,
Mojtaba

Nov 16 '05 #2
also bear in mind Mojtaba that the SqlAdapter will dynamically open and
close the connection for you, so you should always let it do so (as opposed
to manually opening and closing the connection).

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:Ot****************@tk2msftngp13.phx.gbl...
Hi Mojtaba,

In designer you only design the connection - it won't open it for you thus
it won't make much difference.
Though I preffer to create it by code right before I need it and dispose it as soon as possible.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Mojtaba Faridzad" <mf*******@hotmail.com> wrote in message
news:Oc**************@TK2MSFTNGP15.phx.gbl...
Hi,

(newbie in C#) is it a good idea to use SQL Connection, SQL Data
Adapter,... in C#? when I am design a form, I can use SQL Connection and
set the properties to connect to a database. I guess after unloading the
form, this connection will be closed. but as I know, it's better to open a connection when we need it and after using, we should close it. I can do
it without using SQL Connection component (by using SqlConnection class). now which one is better? using SQL Connection is very easy but I'd like to have the best performance.

thanks,
Mojtaba


Nov 16 '05 #3
Hi Mark,

"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:e2**************@tk2msftngp13.phx.gbl...
also bear in mind Mojtaba that the SqlAdapter will dynamically open and
close the connection for you, so you should always let it do so (as
opposed
to manually opening and closing the connection).


I tend to disagree.
You should manually open the connections if you have more than one operation
to do within the same connection.
Not to speak about Update when it is supposed to be a part of transaction
:-)

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com
Nov 16 '05 #4
thanks Mark!

so a combination of SqlConnection, SqlDataAdapter, SqlCommand, and DataSet
(by drag and drop it from toolbox) has the same performance as open them in
source code? in source code, I use a "try" block to open the connection and
fill the DataAdapter and close the connection.

the reason of asking this question is that I am reading "Prof. C# 2nd
Edition" which teaches programming method of connection to a database. but I
downloaded a sample program which opens and works with data just by toolbox
components. I confused a little bit which method it's better.

thanks again

"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:e2**************@tk2msftngp13.phx.gbl...
also bear in mind Mojtaba that the SqlAdapter will dynamically open and
close the connection for you, so you should always let it do so (as
opposed
to manually opening and closing the connection).

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:Ot****************@tk2msftngp13.phx.gbl...
Hi Mojtaba,

In designer you only design the connection - it won't open it for you
thus
it won't make much difference.
Though I preffer to create it by code right before I need it and dispose

it
as soon as possible.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Mojtaba Faridzad" <mf*******@hotmail.com> wrote in message
news:Oc**************@TK2MSFTNGP15.phx.gbl...
> Hi,
>
> (newbie in C#) is it a good idea to use SQL Connection, SQL Data
> Adapter,... in C#? when I am design a form, I can use SQL Connection
> and
> set the properties to connect to a database. I guess after unloading
> the
> form, this connection will be closed. but as I know, it's better to
> open a > connection when we need it and after using, we should close it. I can
> do
> it without using SQL Connection component (by using SqlConnection class). > now which one is better? using SQL Connection is very easy but I'd like to > have the best performance.
>
> thanks,
> Mojtaba
>



Nov 16 '05 #5
thanks Miha. I forgot to mention it on my previous post :)

just I wanted to let you know that I am using MySQLDirect connection (not
SqlConnection) but both they have the same components.

Mojtaba

"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:e2**************@tk2msftngp13.phx.gbl...
also bear in mind Mojtaba that the SqlAdapter will dynamically open and
close the connection for you, so you should always let it do so (as
opposed
to manually opening and closing the connection).

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:Ot****************@tk2msftngp13.phx.gbl...
Hi Mojtaba,

In designer you only design the connection - it won't open it for you
thus
it won't make much difference.
Though I preffer to create it by code right before I need it and dispose

it
as soon as possible.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Mojtaba Faridzad" <mf*******@hotmail.com> wrote in message
news:Oc**************@TK2MSFTNGP15.phx.gbl...
> Hi,
>
> (newbie in C#) is it a good idea to use SQL Connection, SQL Data
> Adapter,... in C#? when I am design a form, I can use SQL Connection
> and
> set the properties to connect to a database. I guess after unloading
> the
> form, this connection will be closed. but as I know, it's better to
> open a > connection when we need it and after using, we should close it. I can
> do
> it without using SQL Connection component (by using SqlConnection class). > now which one is better? using SQL Connection is very easy but I'd like to > have the best performance.
>
> thanks,
> Mojtaba
>



Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sandy Norton | last post by:
Hi folks, I have been mulling over an idea for a very simple python-based personal document management system. The source of this possible solution is the following typical problem: I...
33
by: Jerry Boone | last post by:
A long time ago Larry Linson (MVP contributor to this group) made a point to me that mdb's could do anything ADP's (Access Projects) could by using linked tables to leverage Sql server databases. ...
3
by: Rob Thomas | last post by:
Hi, I'm just getting started with real OO design and programming and am after a little advice. Basically, I've got a Customer class and an Agency class. The Agency class inherits all the...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
54
by: sam.s.kong | last post by:
Hi! I've been programming ASP for 5 years and am now learning PHP. In ASP, you can use GetRows function which returns 2 by 2 array of Recordset. Actually, it's a recommended way in ASP when you...
1
by: booksnore | last post by:
I have an application where a have a single admin database and multiple customer databases containing the customer's warehouse data. In the admin database I hold a user table and also a client...
20
by: Dr. Colombes | last post by:
For a personal Web site with modest throughput and interactivity demans, I'm interested in your recommendation(s) for good (cheap, reliable, Linux friendly, very little, if any, sponsor...
7
by: Lauren Quantrell | last post by:
I used to force a new connection between my Access 2K database and a SQL Server backend every time the user launches the application, but it seemed very slow, in fact using a timer function, I...
0
by: Sinex | last post by:
Hi, Am writing a webservice thats gonna access a DB and return data. The connection string needs to be configurable. So am thinking of storing it in the web.config file. But then is it a good idea...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.