1. If the website does not require database installation.
1. Open an existing website-> Publish a website-> OK.
2. Choose solution> new project> other project type> installation and deployment> Web installation project> OK.
3. Add files from published websites to the file system> Web applications.ProgramFolder. You can also drag the file directly to it, with the same effect.
4. Generate a web installation project. Simple packaging is complete.
2. Deploy Web applications with databases (SQL Server)
1. Open an existing website-> Publish a website-> OK (get the content to be published ).
2. Choose solution> new project> other project type> installation and deployment> Web installation project> OK.
3. Add the content to be released to the installation project (includingTable. SQL file).
4. Select the Web installation project> User Interface Editor. at startup, choose add Dialog Box> text box (a)> right-click Properties,
Edit1label attribute and type: Database Name :. Edit1property property and type customtexta1. Edit1value property and type: MDB. Edit2label attribute and type: Server Name :. Edit2property property and type customtexta2. Set the edit2value attribute and enter the localhostedit3label attribute, and enter the username :. Edit3value property and type: SA. Edit3property property and type customtexta3. Edit4label property and type: Password :. Edit4property property and type customtexta4.
Move to the appropriate location.
5. Add the new class library project (dbinstaller) to the current solution, and add the installer class (ClassCodeUnder ).
6. Add the Web installation project output and select dbinstaller.
7. Select "Web installation project"> "Custom operation Editor"> "Install"> "add custom operation", and find the file added in Step 6,
Set the attributes of the added file customactiondata: /dbname = [edita1]/Server = [edita2]/user = [edita3]/Pwd = [edita4]/targetdir = "[targetdir] \"
8. generate.
Method code in the class:
Code
Public Override Void Install (idictionary statesaver)
{
Base . Install (statesaver );
String Connstr = String . Format ( " Data Source = {0}; user id = {1}; Password = {2}; persist Security info = false; packet size = 4096 " , This . Context. Parameters [ " Server " ], This . Context. Parameters [ " User " ], This . Context. Parameters [ " PWD " ]);
Executesql (connstr, " Master " , " Create Database " + This . Context. Parameters [ " Dbname " ]);
Stringbuilder sb = This . Getsqlfile ( " Table. SQL " );
Executesql (connstr, This . Context. Parameters [ " Dbname " ], SB. tostring ());
}
// Obtain the script in the SQL File
Private Stringbuilder getsqlfile ( String Pfilename) {
Stringbuilder sqltemp = New Stringbuilder ();
Sqltemp. append (file. readalltext ( This . Context. Parameters [ " Targetdir " ] + " \\ " + Pfilename, system. Text. encoding. getencoding ( " Gb2312 " )));
Return Sqltemp;
}
Private Void Executesql ( String Connstr, String Databasename, String SQL)
{
Using (Sqlconnection Conn = New Sqlconnection (connstr ))
{
Sqlcommand cmd = New Sqlcommand (SQL, Conn );
Conn. open ();
Conn. changedatabase (databasename );
Try
{
Cmd. executenonquery ();
}
Finally
{
Conn. Close ();
}
}
}