2011-08-02 60 views
1

我需要通過使用SqlString使用Wix創建一個名爲MyDB的簡單數據庫。以下是我的代碼片段。對於該行(SQL =「CREATE DATABASE MyDB」),我可能知道這是否正確,它會創建'MyDB'數據庫嗎?我已經正確設置了用戶和服務器屬性。但是,這允許安裝,但它不創建數據庫。任何人都可以指出什麼是錯誤或缺失?Wix:如何使用SqlScript創建數據庫

<sql:SqlDatabase Id='SqlDatabase' Database='master' User='SQLUser' Server='[SQLSERVER]' 
       CreateOnInstall='no' DropOnUninstall='no' ContinueOnError='yes'> 

       <sql:SqlString Id="InitialCreateDB" ExecuteOnInstall="no" ContinueOnError="yes" 
          SQL="CREATE DATABASE MyDB"/> 
      </sql:SqlDatabase> 

在此先感謝。

+1

詳細日誌會告訴你更多關於幕後發生的事情...... –

+0

而SQL事件探查器將提供來自SQL Server端的更多細節。 –

回答

2

爲什麼沒有包含SQL代碼的腳本文件來創建數據庫?

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" 
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension" 
xmlns:sql="http://schemas.microsoft.com/wix/SqlExtension"> 
    <Product Name='SQL app 1.0' Id='DB501C18-86C7-4D14-AEC0-86416A69ABDE' Language='1033' Codepage='1252' 
    Version='1.0.0' Manufacturer='ABC Ltd.'> 
      <Package Id='????????-????-????-????-????????????' Keywords='Installer' Description="SQL App 1.0 Installer" 
       Comments='Comment.' Manufacturer='ABC Ltd.' InstallerVersion='100' 
       Languages='1033' Compressed='yes' SummaryCodepage='1252' /> 
     <Media Id='1' Cabinet='Sample.cab' EmbedCab='yes' /> 
     <User Id="MySQLUser" Name="[SQLUSER]" Password="[SQLUSERPASSWORD]"></User> 
     <Directory Id='TARGETDIR' Name='SourceDir'> 
      <Directory Id='ProgramFilesFolder' Name='PFiles'> 
       <Directory Id='INSTALLDIR' Name='TestSQL'> 
         <Component Id="MySqlComponent" Guid="C50999A0-02FD-42d5-9F65-7375318DD328"> 
         <SqlDatabase Id="MySqlDatabase" Database="MyDatabase" Server="[SQLSERVER]" Instance="[SQLINSTANCE]" 
          CreateOnInstall="yes" DropOnUninstall="yes" User="MySQLUser" ContinueOnError="yes"> 
           <SqlScript Id="CreateDatabase" ExecuteOnInstall="yes" BinaryKey="CreateTablesBin"></SqlScript> 
         </SqlDatabase> 
         </Component> 
       </Directory> 
      </Directory> 
     </Directory> 
     <Binary Id="CreateTablesBin" src="CreateDatabase.sql"></Binary> 
     <Feature Id='Complete' Level='1' Description="Full" Title="Full Installation"> 
      <ComponentRef Id='MySqlComponent' /> 
     </Feature> 
    </Product> 
</Wix> 
+0

注意爲了創建數據庫,在組件下方嵌套SqlDatabase元素。請注意,數據庫屬性是[格式化] [1],因此它可以包含對屬性的引用。 [1]:http://msdn.microsoft.com/library/aa368609.aspx –

2

CreateOnInstall的值設置爲「是」。這將比創建數據庫的一個實例。