ASP. NET database connection instance display:
-
- UsingSystem;
- UsingSystem. Collections;
- UsingSystem. ComponentModel;
- UsingSystem. Data;
- UsingSystem. Drawing;
- UsingSystem. Web;
- UsingSystem. Web. SessionState;
- UsingSystem. Web. UI;
- UsingSystem. Web. UI. WebControls;
- UsingSystem. Web. UI. HTMLControls;
- UsingSystem. Data. SqlClient;
-
- NamespaceExample01
- {
- ///
- /// Summary of WebForm1.
- ///
- Public ClassWebForm1: System. Web. UI. Page
- {
- Private VoidPage_Load (ObjectSender, System. EventArgs e)
- {
- // Place user code here to initialize the page
- Response. Write ("
-
- First ASP. NET database connection instance
-
- ");
- SqlConnection myConnection =NewSqlConnection ("Server = localhost; uid = sa; pwd = sa");
- Try
- {
- MyConnection. Open ();// Open the database link
- Response. Write ("Link successful! ");
- }
- Catch
- {
- Response. Write ("Link failed! ");
- }
- }
-
- # Code generated by region Web Form Designer
- Override Protected VoidOnInit (EventArgs e)
- {
- //
- // CODEGEN: This call is required by the ASP. NET Web form designer.
- //
- InitializeComponent ();
- Base. OnInit (e );
- }
-
- ///
- /// The methods required by the ASP. NET database connection designer-do not use the code editor to modify
- /// Content of this method.
- ///
- Private VoidInitializeComponent ()
- {
- This. Load + =NewSystem. EventHandler (This. Page_Load );
- }
- # Endregion
- }
- }
The instance connecting to the ASP. NET database will be introduced here, hoping to help you.
- Analysis on ASP. NET runtime environment Establishment
- ASP. NET Overview
- Analysis on the advantages of ASP. NET in eleven aspects
- Analysis on ASP. NET database connection
- Configuration Analysis of ASP. NET database connection in web Applications