Hi,
Here is the code I use :
static Regex GoRegex = new Regex("^GO", RegexOptions.Compiled |
RegexOptions.Multiline);
public static bool SqlCmd(string connectionString, string
dbName, string installPath, string sqlScript)
{
try
{
Regex setVar = new Regex(@"^:(setvar|on error)
.*$", RegexOptions.Compiled | RegexOptions.Multiline);
Regex variable = new
Regex(@"\$\((?<variableName>[^\)]+)\)", RegexOptions.Compiled |
RegexOptions.Multiline);
sqlScript =
variable.Replace(setVar.Replace(sqlScript, ""),
match =>
{
switch
(match.Groups["variableName"].Value)
{
case "DatabaseName":
return dbName;
case "DefaultDataPath":
case "DefaultLogPath":
case "CustomDataPath":
case "CustomLogPath":
if
(string.IsNullOrEmpty(installPath))
return
DatabaseHelper.GetDefaultDataPath(connectionString);
return
installPath;
}
return match.Value;
});
log.Debug(sqlScript);
using (SqlConnection connection = new
SqlConnection(connectionString))
{
connection.Open();
var command =
connection.CreateCommand();
foreach (string sql in
GoRegex.Split(sqlScript))
{
command.CommandText = sql;
command.ExecuteNonQuery();
}
}
return true;
}
catch (Exception ex)
{
log.Error(ex);
return false;
}
}
Nicolas Penin
-----Message d'origine-----
De : Nageswara [mailto:[email protected]]
Envoyé : jeudi 24 novembre 2011 16:48
À : [email protected]
Objet : Re: [WiX-users] how to run a sql script in SQLCMD Mode using WIX Tool
Hi Nicolas,
Thanks for the reply. I am new to WIX and would appreciate if you could you
give me an example sample code.
--
View this message in context:
http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/how-to-run-a-sql-script-in-SQLCMD-Mode-using-WIX-Tool-tp7028337p7028595.html
Sent from the wix-users mailing list archive at Nabble.com.
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security threats,
fraudulent activity, and more. Splunk takes this data and makes sense of it. IT
sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
WiX-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wix-users
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
WiX-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wix-users