0

How do i connect my html to a database using asp as server side script

1st Aug 2017, 12:12 PM
Abasi Ekpenyon
Abasi Ekpenyon - avatar
2 odpowiedzi
0
MySql.Data.MySqlClient.MySqlConnection mySqlConnection = new MySql.Data.MySqlClient.MySqlConnection(); mySqlConnection.ConnectionString = “your_ConnectionString”; try { mySqlConnection.Open(); switch (mySqlConnection.State) { case System.Data.ConnectionState.Open: // Connection has been made break; case System.Data.ConnectionState.Closed: // Connection could not be made, throw an error throw new Exception("The database connection state is Closed"); break; default: // Connection is actively doing something else break; } // Place Your Code Here to Process Data // } catch (MySql.Data.MySqlClient.MySqlException mySqlException) { // Use the mySqlException object to handle specific MySql errors } catch (Exception exception) { // Use the exception object to handle all other non-MySql specific errors } finally { // Make sure to only close connections that are not in a closed state if (mySqlConnection.State != System.Data.ConnectionState.Closed) { // Close the connection as a good Garbage Collecting practice mySqlConnection.Close(); } }
1st Aug 2017, 2:15 PM
Corey
Corey - avatar
0
tanks
1st Aug 2017, 2:20 PM
Abasi Ekpenyon
Abasi Ekpenyon - avatar