Connection strings using Web Deploy


#1

Ignore this. I did not know what question to ask so I wrote a long story. I figured it out myself. Hopefully I would have gotten replies if it was not the holiday season. Can I say Bah Humbug to that?

I assume that WebDeploy has a solution to the problem of the variations of connection strings for testing and development and/or local websites and for production and/or remote web sites such as GearHost. Unfortunately I am not experienced with how that is done.

I created a small website and I was able to deploy using Web Deploy. That is wonderful, there are not many hosts that support Web Deploy for shared hosting and really few that support it with free hosting.

I am learning how to use databases with web sites. I know that one of the most useful features of Web Deploy is that it can manage databases too. So I thought I would create a simple sample database application and deploy to GearHost. It works locally; there is a kink I need to solve but that is separate from here. I am using Web Forms and Model Binding and Entity Framework Code First.

So my DbContext class passes a connection string name in the constructor. I am using
LocalSqlServer for the connection string name since I assume it is compatible with GearHost. I am using the developer edition of SQL Server locally and I see that GearHost uses SQL Server Express. I assume that will work but I don’t know how.

In my local system when I tested my application it said that LocalSqlServer already existed so I added a clear in my web.config for my VS project. That worked; I was able to get the database created using context.Database.Initialize and my application adds records and shows them.

I am having problems when I deploy to GearHost. I attempted to solve the problem by removing the connectionstrings in the web.config but I am getting the error “The server was not found or was not accessible”.

I suspect that I could solve the problem using something in ASP.NET Web Deployment using Visual Studio: Web.config File Transformations | Microsoft Docs but the amount of stuff in that is overwhelming. I am hoping I can at least get some specifics about how to do this stuff that is specific to GearHost.

So what is the solution for seamlessly maintaining a connection string locally for development purposes and a different one in the GearHost system for the GearHost connection string?

Update: I am able to connect to my database using SSMS, Visual Studio Server Explorer and Visual Studio SQL Server Object Explorer. I see that the database name is my userid yet the connection string says aspnetdb.mdf. So I overrode the connection string and used the connection string shown in the SQL Server Object Explorer and that works. So there is a problem with the LocalSqlServer connection string.