Analysis of ASP. NET database connection instances

Source: Internet
Author: User

ASP. NET database connection instance display:

 
 
  1.  
  2. UsingSystem;
  3. UsingSystem. Collections;
  4. UsingSystem. ComponentModel;
  5. UsingSystem. Data;
  6. UsingSystem. Drawing;
  7. UsingSystem. Web;
  8. UsingSystem. Web. SessionState;
  9. UsingSystem. Web. UI;
  10. UsingSystem. Web. UI. WebControls;
  11. UsingSystem. Web. UI. HTMLControls;
  12. UsingSystem. Data. SqlClient;
  13.  
  14. NamespaceExample01
  15. {
  16. /// 
  17. /// Summary of WebForm1. 
  18. /// 
  19. Public ClassWebForm1: System. Web. UI. Page
  20. {
  21. Private VoidPage_Load (ObjectSender, System. EventArgs e)
  22. {
  23. // Place user code here to initialize the page 
  24. Response. Write ("
  25.  
  26. First ASP. NET database connection instance
  27.  
  28. ");
  29. SqlConnection myConnection =NewSqlConnection ("Server = localhost; uid = sa; pwd = sa");
  30. Try
  31. {
  32. MyConnection. Open ();// Open the database link 
  33. Response. Write ("Link successful! ");
  34. }
  35. Catch
  36. {
  37. Response. Write ("Link failed! ");
  38. }
  39.  
  40. # Code generated by region Web Form Designer 
  41. Override Protected VoidOnInit (EventArgs e)
  42. {
  43. // 
  44. // CODEGEN: This call is required by the ASP. NET Web form designer. 
  45. // 
  46. InitializeComponent ();
  47. Base. OnInit (e );
  48. }
  49.  
  50. /// 
  51. /// The methods required by the ASP. NET database connection designer-do not use the code editor to modify 
  52. /// Content of this method. 
  53. /// 
  54. Private VoidInitializeComponent ()
  55. {
  56. This. Load + =NewSystem. EventHandler (This. Page_Load );
  57. # Endregion 
  58. }
  59. }

The instance connecting to the ASP. NET database will be introduced here, hoping to help you.

  1. Analysis on ASP. NET runtime environment Establishment
  2. ASP. NET Overview
  3. Analysis on the advantages of ASP. NET in eleven aspects
  4. Analysis on ASP. NET database connection
  5. Configuration Analysis of ASP. NET database connection in web Applications

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.