.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 6th, 2004, 03:15 AM
Belldandy Belldandy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 6 Belldandy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Using Try Catch Finally Statements for connections

I'm trying to make a program that uses a sql server database. I wanted to use the Try-Catch-Finally statement to check if the connection is connected, or if the username/password is right, etc. How do I do this? Thanx!

Reply With Quote
  #2  
Old January 18th, 2004, 08:46 AM
nomi007 nomi007 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Pakistan
Posts: 8 nomi007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
try
//write here the code for the connection
catch ( SQLEXception e )
console.writeline(e.stackTrace)
end try

Reply With Quote
  #3  
Old January 19th, 2004, 02:16 PM
sano sano is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Location: Redmond, WA
Posts: 218 sano User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
The preferred method is (assuming you're using C#) to use the using keyword. This defines a scope at the end of which the SqlConnection object is disposed.

Code:
using ( SqlConnection conn = new SqlConnection( ... ) ) {

    try {
        conn.Open();
    } catch ( SqlExecption sqlEx ) {
        Console.WriteLine( sqlEx.Message );
    } 


}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > Using Try Catch Finally Statements for connections


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT