mit msbuild eine SQL-Datenbank erstellen
-
22-09-2019 - |
Frage
Gibt es ein gutes Tutorial, eine Datenbank für die Erstellung mit msbuild
jean paul Boodhoo tut es mit Nant in diese Post. er legt Eigenschaften in einer Nant-Build-Datei verwendet werden
<properties>
<property name="sqlToolsFolder" value="C:\Program Files\Microsoft SQL Server\90\Tools\Binn"/>
<property name="osql.ConnectionString" value="-E"/>
<property name="initial.catalog" value="Northwind"/>
<property name="config.ConnectionString" value="data source=(local);Integrated Security=SSPI;Initial Catalog=${initial.catalog}"/>
<property name="database.path" value="C:\root\development\databases" />
<property name="osql.exe" value="${sqlToolsFolder}\osql.exe" />
</properties>
kann dann erstellen Sie die Datenbank mit der Befehlszeile wie folgt ..
c:\> build builddb
ich das MSBuild Erweiterungspaket installiert, aber ich konnte nicht finden, wo die Verbindungszeichenfolge eingeben, um die Datenbank
verbindenDanke
RESOLVED
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="constants.proj"/>
<Target Name="QueryDb">
<PropertyGroup>
<_Command>-Q "SELECT * FROM Users"</_Command>
<_Command2>-i test.sql</_Command2>
</PropertyGroup>
<Exec Command="$(sqlcmd) $(_Command)" /><!---->
</Target>
</Project>
und Constants.proj sieht wie folgt aus
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<sqlToolsFolder>C:\Program Files\Microsoft SQL Server\90\Tools\Binn</sqlToolsFolder>
<initialCatalog>NorthwindTest</initialCatalog>
<serverInstance>(local)\SQLEXPRESS</serverInstance>
<configConnectionString>data source=$(serverInstance);Integrated Security=SSPI;Initial Catalog=$(initialCatalog)</configConnectionString>
<osqlExe>"$(sqlToolsFolder)\osql.exe"</osqlExe>
<sqlcmd>$(osqlExe) -U someuser -P somepassword -d $(initialCatalog) -S (local)\SQLEXPRESS</sqlcmd>
<!--<sqlcmd>$(osqlExe) -E -d $(initialCatalog) -S (local)\SQLEXPRESS</sqlcmd>-->
</PropertyGroup>
</Project>
dann am vs Eingabeaufforderung
msbuild db.targets / t: QueryDb
der Befehl, der ausgeführt ist dies "C: \ Programme \ Microsoft SQL Server \ 90 \ Tools \ Binn \ osql.exe" -U einbenutzer -P irgendein -d NorthwindTest -S (local) \ SQLEXPRESS -Q "SELECT * FROM Userprofile"
Danke Sayed
Lösung
Wenn Sie mit dem Ansatz in diesem Beitrag gefolgt bequem sind, dann können Sie einfach, dass auch von MSBuild folgen. Zum Beispiel die Datei constants.proj erstellen (Sie können es nennen, was auch immer Sie mögen) und db.targets (es auch nennen, was Sie wollen). Und dann enthalten diejenigen, wäre so etwas wie:
constants.proj
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<sqlToolsFolder>C:\Program Files\Microsoft SQL Server\90\Tools\Binn</sqlToolsFolder>
<osqlConnectionString>-E</osqlConnectionString>
<initialCatalog>Northwind</initialCatalog>
<configConnectionString>data source=(local);Integrated Security=SSPI;Initial Catalog=$(initialCatalog)</configConnectionString>
<databasePath>C:\root\development\databases</databasePath>
<osqlExe>$(sqlToolsFolder)\osql.exe</osqlExe>
</PropertyGroup>
</Project>
Und dann in db.targets würden Sie nur die Befehlszeile bauen mit diesen Eigenschaften und verwenden Sie die Exec Aufgabe, sie auszuführen, wie folgt aus.
db.targets
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="constants.targets"/>
<Target Name="CreateDb">
<PropertyGroup>
<_Command> ... FILL IN HERE ... </_Command>
</PropertyGroup>
<Exec Command="$(_Command)" />
</Target>
</Project>
Andere Tipps
Die MSBuild Ergänzer enthält Aufgaben (nämlich MSBuild.ExtensionPack.Sql2005
und MSBuild.ExtensionPack.Sql2008
) SQL-Datenbanken zu manipulieren und das folgende Beispiel:
<!-- Create a database -->
<MSBuild.ExtensionPack.Sql2005.Database TaskAction="Create" DatabaseItem="ADatabase2" MachineName="MyServer\SQL2005Instance"/>
<!-- Create the database again, using Force to delete the existing database -->
<MSBuild.ExtensionPack.Sql2005.Database TaskAction="Create" DatabaseItem="ADatabase2" Force="true" Collation="Latin1_General_CI_AI" MachineName="MyServer\SQL2005Instance"/>