Skip to content
August 24, 2013 / windperson

Quartz.net使用SQL CE做jobStore的注意事項

  • 餵給Schelder Factory所需的設定參數要至少有下面這些:

    var properties = new NameValueCollection();
    properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
    properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz";
    
    properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
    properties["quartz.jobStore.dataSource"] = "theSQLCEDS";
    var jobStoreDBFileName= @"QuartzJobStoreDatabase.sdf";
    
    properties["quartz.dataSource.theSQLCEDS.connectionString"] = String.Format(@"Data Source={0};Persist Security Info=False;", jobStoreDBFileName);
    properties["quartz.dataSource.theSQLCEDS.provider"] = "SqlServerCe-400";
    
    properties["quartz.jobStore.useProperties"] = "false";
    properties["quartz.jobStore.clustered"] = "false";
    

    第6,7行的名稱可自訂,和第9,10行符合就可以。第3行必須是使用StdAdoDelegate,不能用SQL Server的;而第10行的”SqlServerCe-400″適用於使用SQL Server CE 4.0以上的版本。

  • 使用不安裝SQL Server CE的方式deploy時,除了需要將SQL Server CE安裝目錄下的Private目錄(C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Private )所有檔案拷貝到執行檔所在的目錄下之外,還需在app.config或web.config的節區內加入如下設定:

    <system.data>
        <DbProviderFactories>
          <remove invariant="System.Data.SqlServerCe.4.0" />
          <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
        </DbProviderFactories>
    </system.data>  
    

    如果還是使用v4.0的話,那個Version=須改為4.0.0.0。

  • 由於目前Quatz.net官方編譯時用的版本是SQL Server CE 4.0,假如開發時是用v 4.0.1而且在deploy時是直接用複製檔案而不安裝SQL Server CE Runtime時,會有找不到System.Data.SqlServerCe.dll的錯誤,需要在app.config或web.config的節區內加入下面的assmebly redirect設定:

    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.1" />
        </dependentAssembly>
      </assemblyBinding>
    </runtime>
    
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: