0

I have a web.config with an entity framework connection string.

That is a sample of such a string:

<add name="MyEntities" connectionString="metadata=res://*/GeneratedModel.MyModel.csdl|res://*/GeneratedModel.MyModel.ssdl|res://*/GeneratedModel.MyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;initial catalog=CRAP;persist security info=True;user id=MyUser;password=password;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

I want to replace the initial catalog aka database name "CRAP" with the new name "TEST"

That code should work as it worked before with another msdeploy.exe command.

I just had to re-structure the $msd variable...

$newActiveTargetDbName = 'TEST';

$msd = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
$iisPath = "MyWebSite/MyService,wmsvc='MyMachine:MyPort/msdeploy.axd',userName='username',password='password'"
& $msd -verb=sync -allowUntrusted -dest=contentPath="$iisPath" -source=contentPath="$iisPath" -setParam=kind="TextFile,match=""(MyEntities.*?catalog=).*?(;)"",scope=web.config$,value=`$1$newActiveTargetDbName`$2"

When I run the above statement I get this connection string in the web.config:

 <add name="$1TEST$2persist security info=True;user id=MyUser;password=password;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

It seems to me that I need somewhere some single/double quotes etc... but I tried actually all kind of combinations and its driving me insane.

How can I fix that?

UPDATE

This is a syntax of the msdeploy statement how it WORKED before I changed it!

$iisServicePath = 'MyWebsite/MyService'; 
$iisPath = "$iisServicePath,computerName=%TargetComputerName%,userName=%NTUserName%,password=%NTUserPassword%"

& "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" `
"-source=contentPath=$iisPath" `
'-verb=sync' `
'-verbose' `
'-allowUntrusted' `
"-dest=contentPath=$iisPath" `
"-setParam=kind=TextFile,match=""(MyEntities.*?catalog=).*?(;)"",scope=web.config$,value=`$1$newActiveTargetDbName`$2";

1 Answer 1

0

I'm not familiar with msdeploy.exe, but I do seem some errors ...

According to the docs, you should be using a colon (:) after the initial parameter name; such as: -dest:contentPath instead of -dest=contentPath.

Additionally (remember, these are guesses cause I'm not familiar with msdeploy.exe):

  1. You're missing the double-quote after TextFile.
  2. You shouldn't have double double-quotes around your match value.
  3. I'm not sure you want the $ after web.config, but I'll leave it alone since it seems to have found your file.

I think you're final line needs to looks something like this:

& $msd -verb=sync -allowUntrusted -dest:contentPath="$iisPath" -source:contentPath="$iisPath" -setParam:kind="TextFile",match="(MyEntities.*?catalog=).*?(;)",scope=web.config$,value="`$1$newActiveTargetDbName`$2"

I hope this helps!

Update

Based on your working one, which I doubt works since it's using % variable names (not how POSH does things), this should do what you want:

& $msd -verb=sync -allowUntrusted -dest=contentPath="$iisPath" -source=contentPath="$iisPath" -setParam=kind=TextFile,match="(MyEntities.*?catalog=).*?(;)",scope=web.config$,value="`$1$newActiveTargetDbName`$2"

Note: there's also several unanswered variables; if you're giving us the full code then there's a ton of errors.

Update 2

After reviewing everything again (with little feedback from the OP), this is how I would do it in PowerShell. I'm not 100% sure that your arguments are correct:

#region Set These Variables
$computername = $env:ComputerName
$nt_username = 'username'
$nt_password = 'password'
$newActiveTargetDbName = 'newActiveTargetDbName'
#endregion

$msd = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
$iisServicePath = 'MyWebsite/MyService'
$iisPath = "${iisServicePath},computerName=${computername},userName=${nt_username},password=${nt_password}"

$start_process = @{
    'FilePath' = $msd;
    'ArgumentList' = @(
        '-verb=sync',
        '-allowUntrusted',
        "-dest=contentPath=""${iisPath}""",
        "-source=contentPath=""${iisPath}""",
        "-setParam=kind=""TextFile,match='(MyEntities.*?catalog=).*?(;)',scope=web.config$,value=`$1${newActiveTargetDbName}`$2"""
    );
    'Wait' = $True
}

$process = Start-Process @start_process

This will give you a command that would look like this in Command Prompt:

"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb=sync -allowUntrusted -dest=contentPath="MyWebsite/MyService,computerName=V-ASUSM32,userName=username,password=password" -source=contentPath="MyWebsite/MyService,computerName=V-ASUSM32,userName=username,password=password" -setParam=kind="TextFile,match='(MyEntities.*?catalog=).*?(;)',scope=web.config$,value=$1newActiveTargetDbName$2"

Note: In the setParam argument, I changed match to single quotes because it looked to me like it was going to mess up your double quotes around kind. If msdeploy.exe doesn't like single quotes, we'll need an actual working command from CMD to figure out what's going on.

Sign up to request clarification or add additional context in comments.

10 Comments

I updated my question with the former working sample. There you see that -dest=contentPath is totally fine. I did like your final line suggestion and get this error: msdeploy.exe : Error: Unrecognized argument 'match=(ErpProductsEntities.*?catalog=).*?(;)'. All arguments must begin with "-".
Your multiline sample throws exceptions/errors. I know you said you are not familiar with msdeploy, but you really should try your sample in a PS IDE else people think that sample might work or be a solution :-)
@Elisabeth, Did you try the single-line example? I had a note after the multiline example: Note: this deliberately not proper posh multi-line syntax because I don't want the back-ticks (`) to break the syntax highlighting.
@Elisabeth, I took out the multi-line example to avoid further confusion. Also, I updated to address your update. Good luck!
@Elisabeth Did you fix it?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.