0

Webアプリケーションをリモートサーバーに公開する際に更新が必要なデータベースがあります。ローカルバージョンのデータベースとリモート(公開された)バージョンを用意したいので、公開バージョンのデータベースに影響を与えずにローカルバージョンにスキーマを変更できます。異なる接続文字列を使用して公開中にデータベースを更新する方法

私はもともと私のプロジェクトのローカルコピーでリモートデータベース接続文字列を使用しましたが、それは正常に公開されました。私はこの接続文字列をローカルデータベースに変更し、公開時の設定でリモート接続文字列を指定し、 '実行時にこの接続文字列を使用する'と 'データベースを更新する'の両方のオプションを選択します。

私は公開しようとする今、私はこのエラーを取得:

Web deployment task failed. (Could not generate deployment script. 
Internal Error. The database platform service with type Microsoft.Data.Tools.Schema.Sql.Sql130DatabaseSchemaProvider is not valid. You must make sure the service is loaded, or you must provide the full type name of a valid database platform service. 
Internal Error. The database platform service with type Microsoft.Data.Tools.Schema.Sql.Sql130DatabaseSchemaProvider is not valid. You must make sure the service is loaded, or you must provide the full type name of a valid database platform service. 
    Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_EXECUTING_METHOD.) 

両方の接続文字列は間違いなく有効である - 私はそれらを使用して、両方のデータベースを更新しました。リモート接続文字列のみを使用して正常に公開しました。ローカルのWeb.configに記載されている別の接続文字列(つまりローカルデータベース)がある場合にのみ失敗するようです。ローカルのWeb.config接続文字列をリモートのWeb.config接続文字列に戻すと、再び動作します。

これが重複している場合の謝罪 - 私は解決策をオンラインで見たことがありますが、私が経験しているものに似ているようなものは見つかりませんでした。

答えて

0

私はこの問題の一部は、データベースがローカルであり、接続文字列で(LocalDb)を使用していたと考えています。これは公開時には接続できないと想定しています。これを別のサーバー上のデータベースに変更し、公開設定を(効果的に)これらの設定に手動で編集しました。

.pubxmlファイル:

<ObjectGroup Name="SomeDatabaseContext" Order="1" Enabled="True"> 
    <Destination Path="Data Source=TestServer;Initial Catalog=SomeDatabase;Persist Security Info=True;User ID=AppUser;Password=SomePassword;Application Name=EntityFramework" Name="Data Source=TestServer;Initial Catalog=SomeDatabase;Persist Security Info=True;User ID=AppUser;Password=SomePassword;MultipleActiveResultSets=True;Application Name=EntityFramework" /> 
    <Object Type="DbDacFx"> 
    <PreSource Path="Data Source=DevServer;Initial Catalog=SomeDatabase.dev;Persist Security Info=True;User ID=AppUser;Password=SomePassword;Application Name=EntityFramework" includeData="False" /> 
    <Source Path="$(IntermediateOutputPath)AutoScripts\ECommerceSiteContext_IncrementalSchemaOnly.dacpac" dacpacAction="Deploy" /> 
    </Object> 
    <UpdateFrom Type="Web.Config"> 
    <Source MatchValue="Data Source=DevServer;Initial Catalog=SomeDatabase.dev;Persist Security Info=True;User ID=AppUser;Password=SomePassword;Application Name=EntityFramework" MatchAttributes="$(UpdateFromConnectionStringAttributes)" /> 
    </UpdateFrom> 
</ObjectGroup> 

のWeb.config:これを行うには

<connectionStrings> 
    <add name="SomeDatabaseContext" connectionString="Data Source=DevServer;Initial Catalog=SomeDatabase.dev;Persist Security Info=True;User ID=AppUser;Password=SomePassword;Application Name=EntityFramework" providerName="System.Data.SqlClient" /> 
</connectionStrings> 

私はサイト上で働いている間、私はデータベースのDEVのバージョンを使用することができます(潜在的に変更する必要が(公開された)バージョンに影響を与えることなく、公開することができます。公開するときに、テストデータベースに対してUpdate-Databaseを覚えていなくても変更を公開することができます。

関連する問題