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 5 1609
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*******@hotm ail.com> wrote in message
news:Oc******** ******@TK2MSFTN GP15.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
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******** ********@tk2msf tngp13.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*******@hotm ail.com> wrote in message news:Oc******** ******@TK2MSFTN GP15.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
Hi Mark,
"Mark Broadbent" <no************ @no-spam-please.com> wrote in message
news:e2******** ******@tk2msftn gp13.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
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******** ******@tk2msftn gp13.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******** ********@tk2msf tngp13.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*******@hotm ail.com> wrote in message news:Oc******** ******@TK2MSFTN GP15.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 >
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******** ******@tk2msftn gp13.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******** ********@tk2msf tngp13.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*******@hotm ail.com> wrote in message news:Oc******** ******@TK2MSFTN GP15.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 >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 accumulate a lot of files (documents, archives, pdfs, images, etc.)
on a daily basis and storing them in a hierarchical file system is
simple but unsatisfactory:
|
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. It's been years since then,
and I still sometimes think about that statement when evaluating the
usefulness of the ADP's I build. Larry and I discussed this technique and
he found it "Credible" (hope you don't mind me quoting you sir) so what the...
|
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 properties and methods from Customer but I have
come accross a couple of problems:
I've got a Save, Add and Delete method in both of the objects. I'm going
|
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 algorithm work with strings that may or may not be
unicode
3) Number of bytes back must either be <= number of _TCHARs in *
sizeof(_TCHAR), or the relation between output size and input size can be
calculated simply. Has to take into account the...
|
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 access DB as it
disconnects the DB earlier.
Also, it's handy as you can directly access any data in the array
without looping.
| |
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 table which holds
the encrypted individual clients connection string to their database. At
the moment on every page of my web app I make a call to the admin
database to retrieve the connection string and then decrypt it (the
web.config holds the...
|
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 advertising) Web
site hosting company (in U.S.).
Thanks!
|
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 determined this
accounted for 90% of the startup time.
I am toying with this method below, where I use
CurrentProject.isConnected. My thought is that Access makes the
connection (based on the info provided in the connection dialog)
anyway, so why...
|
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 to have the connection
string with user/password info sitting there in web.config?
Can it sit there as plain text and can I just use IIS security settings to
determine who can access this file? Or are there any other best practices
for this...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |