In the Venus demonstration site, there are often users to modify the demo password, resulting in other users can not access.
To this end, on the landing page, added a "Initialize database" function, so that even if the user changed the password, other visitors, just reset the database, it is easy to re-enter.
First, use the MSSQL Manage Studio production script to place it under the website.
Here is the sql.aspx source code
<%@ page language= "C #" autoeventwireup= "true"%><%@ import namespace= "System"%><%@ Import namespace= "Sy Stem. Data.sqlclient "%><%@ import namespace=" System.Data "%><%@ import namespace=" System.Web.Configuration "% ><%@ Import namespace= "System.IO"%><%@ Import namespace= "System.Text"%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "><script runat=" server > protected void Btninitdb_click (object sender, EventArgs e) {string Connec tionstring = system.web.configuration.webconfigurationmanager.connectionstrings["ConnectionString"]. ConnectionString; String DBName = "Book.sql"; Try//{//this. Response.Write ("Write connecting String to Web.config<br>"); Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration ( HttpContext.Current.Request.ApplicationPath); // String csname = "ConnectionString"; Connectionstringssection cssection = config. ConnectionStrings; Cssection.connectionstrings[csname]. ConnectionString = ConnectionString; Config. Save (configurationsavemode.modified); }//catch (Exception ex)//{//Response.Write ("write Web. config data error:" + ex.) ToString ()); Return } SqlConnection conn = null; try {using (StreamReader sr = new StreamReader (Server.MapPath ("~/app_data/" +dbname)) { Create New Connection to database conn = new SqlConnection (connectionString) ; Conn. Open (); while (!SR. Endofstream) {StringBuilder sb = new StringBuilder (); SqlCommand cmd = conn. CreateCommand (); while (!SR. Endofstream) {string s = Sr. ReaDline (); if (s! = null && s.toupper (). Trim (). Equals ("GO")) {break; } sb. Appendline (s); }//Execute T-SQL against the target database Cmd.commandtext = sb. ToString (); Cmd.commandtimeout = 3000; Cmd. ExecuteNonQuery (); }} Response.Redirect ("default.aspx"); Page.registerclientscriptblock ("Success", "<script>alert (' installation is successful, system automatically jumps to the homepage"); Window.location= '. /default.aspx '; </script> "); } catch (Exception ex) {this. Response.Write (String.Format ("An error occured: {0}", ex. ToString ())); Return } finally {if (conn! = null) {try { Conn. Close (); Conn. Dispose (); } catch (Exception ee) {this. Response.Write (String.Format @ Could not close the connection. Error was {0} ", EE. ToString ())); }}}}</script>Note the Red section, if you use it, modify the information for your own database.
In this way, you will never worry about the user to modify the database account arbitrarily
You can also click here to download the source code Http://files.cnblogs.com/files/mqingqing123/SQL.rar
Install script to run the database with ASP.