1

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=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\SEDGRAIC.mdf;integrated security=true;connect timeout=60;MultipleActiveResultSets=True;App=EntityFramework&quot;" 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=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\SEDGRAIC.mdf;integrated security=true;connect timeout=60;MultipleActiveResultSets=True;App=EntityFramework&quot;" 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

culebrin
  • 125
  • 1
  • 15
  • 1
    Does the client machine have localdb installed? – ErikEJ Nov 19 '14 at 17:39
  • Yes, the client has the LocalDB msi file installed – culebrin Nov 19 '14 at 19:57
  • And does the v11.0 instance exist - you can use sqllocaldb.exe to check – ErikEJ Nov 19 '14 at 20:34
  • I used the tool (sqllocaldb.exe), created an instance, connected to it and all... all of this on the client machine... – culebrin Nov 19 '14 at 20:56
  • And you are 100% sure 4,0,3 is installed? It is required 4,0,0 is not enough – ErikEJ Nov 19 '14 at 21:20
  • The method I used to check the framework version on the client is the following: regedit=>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full : and the resulting value at the key "Version" is: 4.0.30319 – culebrin Nov 19 '14 at 21:32
  • 1
    I think that method is not enough: http://stackoverflow.com/questions/8065002/how-can-i-find-out-if-net-4-02-is-installed – ErikEJ Nov 20 '14 at 10:46
  • Ok, interesting, think we're getting somewhere, according to that post, I have the nodes: `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.0 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.0,Profile=Client` but not the ones with 4.0.1 neither the ones with 4.0.2, now the question is, with which update can I get those nodes? because I downloaded the latest framework on Microsoft site... – culebrin Nov 20 '14 at 14:28

1 Answers1

1

Thanks to ErikEJ, I found a solution:

The standalone installer of the framework 4 did not contain the update necessary to support LocalDB (even though the version on the registry [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full] says 4.0.30319) Basically, the framework needs the 4.0.2 version of the framework to be installed. One can be misleading thinking that we have a greater version, but actually, we don't.

So, thanks to ErikEJ, find that we have a more compelling way to find the correct version actually is described here: How can I find out if .NET 4.02 is installed?. I only had 2 registry keys instead of the 6 in total that we need.

So we have to install the update to 4.0.2 (KB2544514) to get them. Once installed, now we have the 6 keys needed to use safely a LocalDB database.

Omar

Community
  • 1
  • 1
culebrin
  • 125
  • 1
  • 15