Click here to Skip to main content
15,914,013 members
Home / Discussions / Database
   

Database

 
GeneralRe: SQL - Autonumber - Remove Pin
David Salter20-Jan-05 11:12
David Salter20-Jan-05 11:12 
GeneralSQL UPDATE Multiple Params Pin
Vector718-Jan-05 22:10
Vector718-Jan-05 22:10 
GeneralRe: SQL UPDATE Multiple Params Pin
Colin Angus Mackay18-Jan-05 22:59
Colin Angus Mackay18-Jan-05 22:59 
GeneralRe: SQL UPDATE Multiple Params Pin
Mike Dimmick18-Jan-05 23:02
Mike Dimmick18-Jan-05 23:02 
GeneralRe: SQL UPDATE Multiple Params Pin
Vector719-Jan-05 0:31
Vector719-Jan-05 0:31 
QuestionMSDE installation problem?? Pin
BSRK18-Jan-05 22:06
BSRK18-Jan-05 22:06 
QuestionWhere to keep my connection? Pin
Luis Alonso Ramos18-Jan-05 12:59
Luis Alonso Ramos18-Jan-05 12:59 
AnswerRe: Where to keep my connection? Pin
Colin Angus Mackay18-Jan-05 13:09
Colin Angus Mackay18-Jan-05 13:09 
Luis Alonso Ramos wrote:
What is the best place to keep my SqlConnection object?

I usually create some sort of ApplicationConfiguration class which pulls out the information from the app.config or web.config file and creates a SqlConnection for me.


Luis Alonso Ramos wrote:
Should I have only one application-wide? or one new every time I need it?

I'd say a new one each time you need it. .NET has connection pooling so you don't need to worry about storing one somewhere for when you need it. Also, if you create a new connection each time you need it you can potentially have two connections open at the same time.


Luis Alonso Ramos wrote:
Where should I open it? every time I'm going to use it? or at the beginning of my application?

I'd say open it, use it, close it. Like this:
SqlConnection conn = MyAppConfig.GetDatabaseConnection();
try
{
    conn.Open();
    // Do the database query.
}
catch(SqlException ex)
{
    // Catch any exceptions
}
finally
{
    conn.Close()
}


Does this help?


Do you want to know more?
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums


Upcoming talk:
SELECT UserName, Password FROM Users
-- Getting unauthorised access to a SQL Server, and how to prevent it.

AnswerRe: Where to keep my connection? Pin
Rob Graham18-Jan-05 15:41
Rob Graham18-Jan-05 15:41 
GeneralUsing NULLs in database fields Pin
Luis Alonso Ramos18-Jan-05 12:19
Luis Alonso Ramos18-Jan-05 12:19 
GeneralRe: Using NULLs in database fields Pin
Colin Angus Mackay18-Jan-05 12:49
Colin Angus Mackay18-Jan-05 12:49 
GeneralRe: Using NULLs in database fields Pin
Luis Alonso Ramos18-Jan-05 14:15
Luis Alonso Ramos18-Jan-05 14:15 
QuestionWhat is wrong with this SQL code Pin
Asabere18-Jan-05 9:02
Asabere18-Jan-05 9:02 
AnswerRe: What is wrong with this SQL code Pin
Colin Angus Mackay18-Jan-05 13:02
Colin Angus Mackay18-Jan-05 13:02 
GeneralNavigate in dataset Pin
hendriks17-Jan-05 4:57
hendriks17-Jan-05 4:57 
GeneralMS-SQL to Oracle Pin
spsharma16-Jan-05 22:10
spsharma16-Jan-05 22:10 
GeneralRe: MS-SQL to Oracle Pin
Member 80036019-Jan-05 1:27
Member 80036019-Jan-05 1:27 
GeneralRe: MS-SQL to Oracle Pin
basementman20-Jan-05 4:44
basementman20-Jan-05 4:44 
GeneralOle db connecting problem Pin
lisoft16-Jan-05 21:50
lisoft16-Jan-05 21:50 
GeneralRe: Ole db connecting problem Pin
Rob Graham18-Jan-05 6:56
Rob Graham18-Jan-05 6:56 
GeneralADO Execute stored procedure Pin
willtein16-Jan-05 21:11
willtein16-Jan-05 21:11 
GeneralADO: Fields::GetItem() with number Pin
wilsonian16-Jan-05 9:22
wilsonian16-Jan-05 9:22 
GeneralRe: ADO: Fields::GetItem() with number Pin
Edbert P17-Jan-05 12:41
Edbert P17-Jan-05 12:41 
GeneralRe: ADO: Fields::GetItem() with number Pin
wilsonian17-Jan-05 13:17
wilsonian17-Jan-05 13:17 
GeneralRe: ADO: Fields::GetItem() with number Pin
Rob Graham17-Jan-05 16:15
Rob Graham17-Jan-05 16:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.