Last post Sep 09, 2013 04:56 PM by PatriceSc
Sep 09, 2013 05:05 AM|TheNutCracker|LINK
The exception stated in the Subject of my message is being thrown when trying to load up my MVC default home page.
When I am debugging my website on IIS Express there is no connection string node in the web.config file for my Code First database. It just connects and works.
After I publish my website to IIS 8.0(to the inetpub/wwwroot folder) there is a connection string that has been added to the root web.config file of my web application. The connection string is:
<add name="WebApp1.Models.myDbContext" connectionString="WebApp1.Models.myDbContext_ConnectionString" providerName="System.Data.SqlClient" />
I am leaving the remote connection string box empty in the publish dialog so this is being added automatically.
Is the connectionString supposed to be as it is shown here or is this some type of token that is supposed to be transformed in the publish process but isn't getting transformed?
I am using "Code First" and my database initialization strategy is CreateDatabaseIfNotExists.
Sep 09, 2013 10:51 AM|PatriceSc|LINK
A connection string for EF is supposed to be something like as show here :
http://msdn.microsoft.com/en-us/data/jj556606.aspx (that is basically a usual ADO.NET connection string for EF code first, it has a metadatapart and a usual ADO.NET connection string for DB first).
It seems that if you left the box empty, it just writes a place holder that you are supposed to replace yourself by a suitable value ?
Sep 09, 2013 04:03 PM|TheNutCracker|LINK
Wow, I hope your theory isn't correct. That would appear to be a really poor decision on Microsofts part. Add the connection string for me automatically but don't put it in the correct format? I don't think that's what's going on.
Entity framework code first is capable of dynamically generating a connection string for your database if you don't supply one. If I comment out the connection string to my DbContext in the web.config file that the "publish" method inserts as I posted above....it
actually gets around the exception being thrown.
Entity framework will accept literal connection strings or named connection strings when supplied. Im not exactly sure what the problem is just yet.
Sep 09, 2013 04:56 PM|PatriceSc|LINK
Which version of VS 2012 is this ? Update 3 ? What if you create a package without publishing it so that you can give a look at its content
What I see here is that the connection string in web.config is $(ReplacableToken_<initial name>-Web.config Connection String_0) and that the parameters file contains a replacement such as :
<setParameter name="<initial name>-Web.config Connection String" value="Data Source=MyServer;Initial Catalog=MyDb;User ID=MyUserID;Password=MyPasssword" />
I'm not sure it would work because of the additional _0 but it seems quite logical and near. Could it be that for some reason you have something wrong.
BTW if I remember you say yiou have no connection string at all in your web.config yet the publishing wizard is able to propose such a setting ? My understanding was it should allows to configure *existing* connectionstring ?
Could it be that this connection string is in your initial web.config but is not used because the name doesn't match (and perhaps even its content is wrong) but eht you then try to use this wrong value once deployed.
At least creating the package on disk, should allow to inspect this package and see if the error happens when the package is created or deployed.