Automatically install databases under asp

Source: Internet
Author: User

<! -- # Include file = "../inc/md5.asp" -->
<%
'On Error Resume Next
Dbhost = request. Form ("dbhost ")
Dbname = request. Form ("dbname ")
Dbnew = request. Form ("dbnew ")
Dbuser = request. Form ("dbuser ")
Dbpw = request. Form ("dbpw ")
User_code = request. Form ("user_code ")
User_pwd = request. Form ("user_pwd ")
Formqian = request. Form ("formqian ")&"_"
Set conn = server. createobject ("adodb. connection ")
Connstr = "provider = sqloledb; data source =" & dbhost & "; User ID =" & dbuser & "; pwd =" & dbpw & "; Initial Catalog = master"
Conn. open connstr
If dbnew = "1" then
Conn.exe cute ("create database" & dbname & "ON (NAME = 'jxc _ dat ', FILENAME ='" & server. mappath (".. /data/"& dbname &". mdf ") &" ') log on (NAME = 'jxc _ log', FILENAME =' "& server. mappath (".. /data/"& dbname &" _ log. ldf ")&"')")
End if

If Err Then
Err. Clear
Set Conn = Nothing
%>
<Script language = "javascript">
Alert ("database connection failed. Please check database settings! ")
Window. history. go (-1)
</Script>
<%
Response. End
End If

If dbnew = "0" then
Conn.exe cute ("declare hcforeach cursor global for select 'Kill '+ rtrim (spid) from master. dbo. sysprocesses where dbid = db_id ('"& dbname &"') exec sp_msforeach_worker '? '")
End if
SQL = "use master Restore database" & dbname & "from disk = '" & server. mappath ("../data/start. dat") & "' with REPLACE"
Conn.exe cute (SQL)
Conn. close ()

Connstr = "provider = sqloledb; data source =" & dbhost & "; User ID =" & dbuser & "; pwd =" & dbpw & "; Initial Catalog =" & dbname
Conn. open connstr
Conn.exe cute ("update login set user_code = '" & user_code & "', user_pwd = '" & md5 (user_pwd )&"'")
Conn. close

 

Set conn = nothing

Set objfso = Server. CreateObject ("Scripting. FileSystemObject ")
Set fy = objfso. createtextfile (server. mappath ("../data/install. lock"), true)
Set fy = objfso. OpenTextFile (server. mappath ("../conn. asp"), 2)
Set fw = objfso. OpenTextFile (server. mappath ("conn.txt"), 1)
Tempconn2 = fw. Readall ()
Tempconn2 = replace (tempconn2, "{$ dbhost}", dbhost)
Tempconn2 = replace (tempconn2, "{$ dbname}", dbname)
Tempconn2 = replace (tempconn2, "{$ dbuser}", dbuser)
Tempconn2 = replace (tempconn2, "{$ dbpw}", dbpw)
Tempconn2 = replace (tempconn2, "{$ formqian}", formqian)
Fy. WriteLine (tempconn2)
%>
<Script type = "text/javascript"> document. getElementById ("laststep "). disabled = false; document. getElementById ("laststep "). value = 'installation successful, click Next '; </script>
<% End if %>

 

Refer to Jin mancang (WEB) Inventory Management System

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.