Initially I developed an application (winforms/c#) using VS 2013: framework 4.5, SQL Server 2012 and EntityFramework 6, but due a change on the user clients requirements and scenario, the application was migrated to: framework 4.0.3, LocalDB 2012 and EntityFramework 6.
To migrate projects frameworks I just change the targeted version, re-installed references (EntityFramework included) and checked the app.config.
And to migrate mdfs, in VS, created a Data Connection, using SQL Server DataProvider, ServerName (LocalDB)\v11.0, WindowsAuthentication and Attached the database file, that showed me a warning that it will be affecting the database, and then the connection was created, this connection was used to create the ADO Entity Data Models.
To deploy on clients I used a WIX project.
When I deploy on a machine that has the Framework 4.0.3 installed, the application crashes with the error:
"Underlying provider failed on open" and the innerexception was "A network-related or instance-specific occurred while establishing ..."
on
using (var dbContext = new SEDGRAICEntities()) <<-- Crashes Here
{
try
{
var baseubigeo = (from u in dbContext.T_MAE_UBIGEOCCPP
select u.id_departamento.Trim() + u.id_provincia.Trim() + u.id_distrito.Trim() + u.id_centropoblado.Trim()).ToList();
var query = from x in baselocalcp
where !baseubigeo.Contains(x)
select x;
result = query.AsEnumerable<string>().ToList();
}
catch (DbEntityValidationException dbEEx)
{
dbContext.Database.Connection.Close();
dbContext.Dispose();
throw dbEEx;
}
catch (Exception Ex)
{
dbContext.Database.Connection.Close();
dbContext.Dispose();
throw Ex;
}
}
SEDGRAICEntities:
public partial class SEDGRAICEntities : DbContext
{
public SEDGRAICEntities()
: base("name=SEDGRAICEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<DIS2K06> DIS2K06 { get; set; }
public virtual DbSet<T_MAE_UBIGEOCCPP> T_MAE_UBIGEOCCPP { get; set; }
public virtual DbSet<T_SEDD_GEOLOCALIZACIONCCPP> T_SEDD_GEOLOCALIZACIONCCPP { get; set; }
public virtual ObjectResult<UbigeoValidacion> sp_ValidaUbigeoWGS84(string p_ver, string p_xmlData, Nullable<bool> p_boolGeo)
{
var p_verParameter = p_ver != null ?
new ObjectParameter("p_ver", p_ver) :
new ObjectParameter("p_ver", typeof(string));
var p_xmlDataParameter = p_xmlData != null ?
new ObjectParameter("p_xmlData", p_xmlData) :
new ObjectParameter("p_xmlData", typeof(string));
var p_boolGeoParameter = p_boolGeo.HasValue ?
new ObjectParameter("p_boolGeo", p_boolGeo) :
new ObjectParameter("p_boolGeo", typeof(bool));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<UbigeoValidacion>("sp_ValidaUbigeoWGS84", p_verParameter, p_xmlDataParameter, p_boolGeoParameter);
}
}
The SEDGRAICEntities connectionstring on App.Config is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<appSettings>
<add key="BusinessID" value="20102010201" />
<add key="BusinessName" value="TESTBUSINESS" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<connectionStrings>
<add name="SEDGRAICCUADROSEntities" connectionString="metadata=res://*/erCUADROSmodel.csdl|res://*/erCUADROSmodel.ssdl|res://*/erCUADROSmodel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\SEDGRAIC.mdf;integrated security=true;connect timeout=60;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="SEDGRAICEntities" connectionString="metadata=res://*/erSEDGRAICmodel.csdl|res://*/erSEDGRAICmodel.ssdl|res://*/erSEDGRAICmodel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\SEDGRAIC.mdf;integrated security=true;connect timeout=60;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
The thing is when I deploy the exact same installer on a machine with framework 4.5, and the app works perfectly.
I re-created the solution using VS 2010 with framework 4.0.3, with the same results.
The requirement it's to maintain framework 4.0.3, in order to keep compatibility with the clients machines, so I can't use framework 4.5.
I don't understand why the application needs framework 4.5 to work if I removed all (I think) dependencies and even recreated the solution.
Please help me with this.
Omar