none
How to reference a different server after project deployment for project using Entity Framework (6.0) RRS feed

  • Question

  • I created a (C#) winform project (VS2012) on a development computer using a local sql server (2008 R2 SP1) and Entity Framework 6.0 (6.?). I need to deploy this project now to a production computer/server using a production sql server (also 2008 R2).   What is the best practice for changing the connection string of DBcontext at runtime?  Could the user enter a server in a textbox and assign that to the connection string property of DBcontext?

      

    Rich P

    Wednesday, December 17, 2014 12:19 AM

Answers

  • I created a (C#) winform project (VS2012) on a development computer using a local sql server (2008 R2 SP1) and Entity Framework 6.0 (6.?). I need to deploy this project now to a production computer/server using a production sql server (also 2008 R2).   What is the best practice for changing the connection string of DBcontext at runtime?  Could the user enter a server in a textbox and assign that to the connection string property of DBcontext?

    The appropriate thing to do is change the server name in the connectionstring manually and deploy. If this is a project that creates an exe, then a programname.exe.config is created from the app.config that is in the project. The programname.exe.config must accompany the programname.exe and be in the same location as the programname.exe so that .Net can find the configuration information.

    Maybe, you need to look into various environment builds you can do in VS, instead of having some user do something like you are talking about.

    1) Debug

    2) Release

    3) Test

    4) QA

    5) Production

    http://msdn.microsoft.com/en-us/library/kwybya3w.aspx

    http://msdn.microsoft.com/en-us/library/kkz9kefa.aspx

    http://stackoverflow.com/questions/20690452/transform-app-config-for-3-different-environment

    Wednesday, December 17, 2014 4:50 AM

All replies

  • I created a (C#) winform project (VS2012) on a development computer using a local sql server (2008 R2 SP1) and Entity Framework 6.0 (6.?). I need to deploy this project now to a production computer/server using a production sql server (also 2008 R2).   What is the best practice for changing the connection string of DBcontext at runtime?  Could the user enter a server in a textbox and assign that to the connection string property of DBcontext?

    The appropriate thing to do is change the server name in the connectionstring manually and deploy. If this is a project that creates an exe, then a programname.exe.config is created from the app.config that is in the project. The programname.exe.config must accompany the programname.exe and be in the same location as the programname.exe so that .Net can find the configuration information.

    Maybe, you need to look into various environment builds you can do in VS, instead of having some user do something like you are talking about.

    1) Debug

    2) Release

    3) Test

    4) QA

    5) Production

    http://msdn.microsoft.com/en-us/library/kwybya3w.aspx

    http://msdn.microsoft.com/en-us/library/kkz9kefa.aspx

    http://stackoverflow.com/questions/20690452/transform-app-config-for-3-different-environment

    Wednesday, December 17, 2014 4:50 AM
  • Thank you for this information.

    Rich P

    Thursday, December 18, 2014 12:33 AM
  • The below bat file is called BuildEbableDebug.bat that builds all the solutions for the application for a Debug configuation. One doesn't have to be up in VS IDE doing the builds on their machine for each solution that makes up the solution as a whole. One just double-clicks the bat file in  Explorer and the build takes off. If there are any complile errors and warnings, they are displayed in the Command Prompt window as the bat file executes and builds each solutions.   It may be of intrest to you.                       

    REM Builds the Maintain solution in Debug mode.
    REM Visual Studio is not required but the .NET 4.0 SDK must be installed (http://www.microsoft.com/download/en/details.aspx?displayLang=en&id=8279).

    ..\DotNet\Tools\NuGet\nuget.exe restore ..\DotNet\DocService\DocService.sln -sourcehttp://daypdsv-build/NuGetServer/NuGet;https://www.nuget.org/api/v2
    ..\DotNet\Tools\NuGet\nuget.exe restore ..\DotNet\Enable.MT.sln -source http://daypdsv-build/NuGetServer/NuGet;https://www.nuget.org/api/v2
    ..\DotNet\Tools\NuGet\nuget.exe restore ..\DotNet\Enable.PT.sln -source http://daypdsv-build/NuGetServer/NuGet;https://www.nuget.org/api/v2
    C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe ../DotNet/DocService/DocService.sln /t:Rebuild /p:Configuration=Debug /p:VisualStudioVersion=12.0 /m
    pause
    C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe ../DotNet/Enable.MT.sln /t:Rebuild /p:Configuration=Debug /p:VisualStudioVersion=12.0 /m
    pause
    C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe ../DotNet/Enable.PT.sln /t:Rebuild /p:Configuration=Debug /p:VisualStudioVersion=12.0 /m
    pause

    Friday, December 19, 2014 2:53 PM