2、直接在 安装设计视图中创建连接后,直接创建一个sqlscript,会在安装的时候直接执行。这样的话就的提前知道安装的位置(这是不可能的),于是就直接写成可替换的字符串,然后使用 text replacement 选项卡,设置替换项。其中,sqlscript如下:
USE master; GO -- Drop database if it exists. IFEXISTS (SELECT name FROM sys.databases WHERE NAME ='dmydb') DROPDATABASE dmydb; GO CREATEDATABASE dlbj ONPRIMARY (FILENAME = '%TEXT_TO_BE_REPLACED_IN_THE_FILE%/dmydb.mdf') LOGON (FILENAME = '%TEXT_TO_BE_REPLACED_IN_THE_FILE%/dmydb_log.LDF') FOR ATTACH; GO
function UpdateKey( svFilePath, svFindEntry, svNewEntry) NUMBER nResult, nvLineNumber; STRING WebConfigFile, svReturnLine; begin // build the path to the Web.Config WebConfigFile = svFilePath ^"web.config"; // search the file for the key we specify nResult = FileGrep( WebConfigFile, svFindEntry, svReturnLine, nvLineNumber, RESTART ); switch(nResult) case0: // Since this line normally appears twice in our web.config file, we're // checking for the existence of a 2nd match and updating it instead. //If there is no 2nd match, go ahead and update the one we find. if ( svFindEntry ="connectionString" ) then nResult = FileGrep( WebConfigFile, svFindEntry , svReturnLine, nvLineNumber, CONTINUE ); if ( nResult <0 ) then FileGrep( WebConfigFile, svFindEntry, svReturnLine, nvLineNumber, RESTART ); endif; endif; // once we find the key, update (replace) it with our new values if ( FileInsertLine( WebConfigFile, svNewEntry, nvLineNumber, REPLACE ) <0 ) then // hmmm we couldn't update the value of the key MessageBox( "Unable to update Web.Config file.", SEVERE ); endif; case-2: // File Not Found MessageBox( "Web.Config file not found.", SEVERE ); case-4: // EOF reached MessageBox( svFindEntry +" key not found.", SEVERE ); default: //unknown error MessageBox( "An unknown error has occurred. The Web.Config file has NOT been updated.", SEVERE ); endswitch; end;
-- =============================================
-- Create database for attach
-- =============================================
CREATE DATABASE REC2005_Test
ON PRIMARY (FILENAME = 'c:/dir/test.mdf')
FOR ATTACH
GO
接着在 Text Replacement 中添加一个替换将"c:/dir"替换为"[INSTALLDIR]"即可。当然,上面的例子可能会根据实际情况做些修改,我就不啰嗦了。而在Wise中基本和此类似。