SQL Server CE file location - wpf

I have a problem concerning the folder strcture of my project, which use SQL Server CE 3.5 (private deploy). The following pic show the folder structure that is fine (no error)
But I wold like to reorganize the folder as follows:
This throws an error, "Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8080. Install the correct version of SQL Server Compact. Refer to KB article 974247 for..."
So I tried to add the probing path in my config file:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="dll"/>
<dependentAssembly xmlns="">
<assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="3.5.1.0-3.5.1.50" newVersion="3.5.1.50" />
</dependentAssembly>
</assemblyBinding>
but without success. Is there any chance to force my code to check the required DLL in those folders?

No, this is not possible with the SQL Server Compact 3.5 provider, due to some flaws in the folder detection mechanism for private deployment.
Some improvements with private deployment in version 4.0 should enable this, but I assume you are using version 3.5 for a reason.

Related

Configuration issue for web app on iis express

I have a problem in connecting local DB in my web app to run it on iis express.
I developed the application on VS2017 (my os is win10) and to run it on iis I installed sql server 2017 express (until now every thing is ok).
I tested the aap on 2 lap tops have win10 and it is working fine(I installed sqlserver2017exp).
Main pc that I want to run the application on it has win7(not mine) does not supports sqlserver2017exp or 2016 so I installed 2014 but it does not work.
I re-created db by sqlserver2014 and copied it to app_datafolder but I still have same error.
I have lap top has win7 I installed vs2015 to redevelop the application (opened old one and copies code to new one)when I run application by vs2015 I got same error.
I modified web.config many times but I did get correct solution until now.
I need to run application on win7
Error message:
"An attempt to attach an auto-named database for file C:\Users\ITTIHAD FC\Documents\Visual Studio 2015\WebSites\MCL\App_Data\MCL.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."
Thank you
<configuration>
<system.web>
<globalization culture="en-GB" uiCulture="en-US" fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8"/>
<customErrors mode="Off" defaultRedirect="">
<error statusCode="404" redirect="Default.aspx"/>
</customErrors>
<sessionState mode="InProc" cookieless="false" timeout="20"/>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<pages>
<controls>
<add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
</controls>
</pages></system.web>

Cannot read SqlGeography with Dapper

I followed alot of SO questions and I am getting simillar error but I cannot fix this issue.
My Dapper version is 1.50.1
My Microsoft.SqlServer.Types version is 11.0.2
I have added binding redirect in configuration file as follows:
<runtime>
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="10.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
</runtime>
The error I get is:
Error parsing column 2 (Location=POINT (-122.349 47.651) - Object)
While the inner exception is:
[A]Microsoft.SqlServer.Types.SqlGeography cannot be cast to [B]Microsoft.SqlServer.Types.SqlGeography. Type A originates from 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' in the context 'Default' at location 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SqlServer.Types\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Types.dll'. Type B originates from 'Microsoft.SqlServer.Types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' in the context 'Default' at location 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SqlServer.Types\11.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Types.dll'.
If I just do a read to dynamic object everything is all right but if I do read to my own type that has SqlGeography I get this error.
I thought I did all as recommended but it seems I missed something.
Try reading this article on topic SQL CLR Data Types (geometry, geography, and hierarchyid).
Alternatively, try adding this in your connectionString:
"Type System Version=SQL Server 2012", to force SqlClient to load version 11.0 of the assembly
#Marc Gravell did a good job about that see reference below and it will save your life.
SqlGeography
Issue
For ASP.NET applications, add the following line of code to the Application_Start method in Global.asax.cs:
SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
For desktop applications, add the following line of code to run before any spatial operations are performed:
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
The .LoadNativeAssemblies method will get the correct assembly for you base on CPU architecture.
In bin folder you should have this.

Could not load file or assembly 'System.Data.SqlServerCE'

I'm trying to connect to an external .sdf file using VB.NET in VS2012. I'm having issues working with the System.Data.SqlServerCE DLL.
When I don't Copy Local I get the error: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
If I do Copy Local I get: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I have SQL Server Compact version 4 installed, so I'm referencing the DLL in "C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Private". I've tried adding this DLL from other locations and will get the "Found conflicts between different version of the same dependent assembly" warning. If I click on that it'll add the following to the app.config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845DCD8080CC91" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
Once that is added to app.config I get this error:
Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8876. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details.
One thing I noticed earlier was that System.Data.SqlServerCe was not in the C:\Windows\Microsoft.NET\assembly folder. I installed the DLL using gacutil.exe and changed the
<bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1"/>
in app.config to
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0"/>
(4.0.0.0 is the version listed by the gacutil).
This got me past the assembly errors at least. :)
It's too soon to post an answer for myself, so I'll just leave this edit.
I manage to fixed the above issue by using C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Desktop\System.Data.SqlServerCe.dll. So the System.Data.SqlServerCe.dll in path C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Private doesn't work.

Could not load file or assembly Microsoft.Data.OData Version=5.2.0.0 error in Azure Cloud Worker Role using Table Storage

I have a very peculiar issue using Azure Table Storage. I have a .NET 4.5 project in Visual Studio 2012 where I deal with all my Azure Table Storage functions. This project/dll is referenced by two other projects, my MVC website, and my Azure Worker Role. (I am running under the Azure Emulators on my machine, but it also happens when I deploy it to the cloud)
I have the following function that is called when I save or retrieve a record:
internal static CloudTable GetTable(CloudStorageAccount storageAccount, string tableReference)
{
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference(tableReference);
table.CreateIfNotExists();
return tableClient.GetTableReference(table.Name);
}
In my MVC website I have a function that will save a record to a Azure Storage table, and then in my Azure Worker Role there is a service that will read the record.
So both uses the same dll for storage and retrieval, however my MVC project has no issues saving the record, but in my Azure Worker role service when it tries to retrieve the record throws the exception when it attempts to execute "table.CreateIfNotExists();".
Could not load file or assembly 'Microsoft.Data.OData,
Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or
one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT:
0x80131040)
I have done the following already:
Updated all the NuGet packages from the solution level to the latest versions
I went through every project reference to make sure that there are no old dll's or previous versions hanging around, in particular the System.Spatial, Microsoft.WindowsAzure.Configuration, Microsoft.WindowsAzure.ServiceRuntime and Microsoft.ServiceBus, Microsoft.WindowsAzure.Storage, Microsoft.Data.Edm & Microsoft.Data.OData
I have even created a new Cloud Service and WorkerRole project from scratch to make sure it is not something in the current WorkerRole project that is broken.
I have not rolled the dll's back to 5.2 as I had too many issues in other projects where I use features that are specific from 5.3 onwards.
I am currently running all the dll's on 5.5.
When I run the AsmSpy.exe utility found here, I get the following output that I am not 100% sure how to interpret.
> Reference: Microsoft.Data.Edm
> 5.5.0.0 by Microsoft.Data.OData
> 5.5.0.0 by Microsoft.Data.Services.Client
> 5.5.0.0 by Microsoft.WindowsAzure.ActiveDirectory.GraphHelper.2013_04_05
> Reference: System.Spatial
> 5.5.0.0 by Microsoft.Data.OData
> 5.5.0.0 by Microsoft.Data.Services.Client Reference: Microsoft.Data.OData
> 5.5.0.0 by Microsoft.Data.Services.Client
> 5.2.0.0 by Microsoft.WindowsAzure.Storage <-- THIS SEEMS TO BE THE ONE THAT IS CAUSING ISSUES
How I interpret it, is that the Microsoft.WindowsAzure.Storage dll is referencing V 5.2.0.0 of the Microsoft.Data.OData dll, but how do I fix this, if this is the issue? According to the documentation I have seen on the Storage dll is that it is supposed to reference 5.4 and up, not 5.2...?
Opening issue for such an easy to solve issue will not help you.
Put the following addition configuration in your respective config files (web.config for the MVC and app.config for the worker role):
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Note that runtime section is direct descendant of the configuration root element! I'm pretty sure you already have this section in your web.config, because MVC4 uses it to rebind all references to System.Web.MVC to the latest version.
I personally do not expect the SDK to be updated with every new version of every referenced library! This would be madness...
I had a very similar problem but in this case it exception message was;
Could not load file or assembly 'Microsoft.Data.OData,
Version=5.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or
one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT:
0x80131040)
note it was trying to load v5.5.0.0 of the OData assembly.
After some digging around with ILSpy (http://www.ilspy.net) I discovered that Microsoft.WindowsAzure.Storage 2.0.0.0 was explictly referencing Microsoft.Data.OData 5.2.0.0 - which I didn't have as my version was 5.5.0.0.
So the solution was to use the NuGet package manager to uninstall Microsoft.WindowsAzure.Storage, this inturn uninstalled Microsoft.Data.OData 5.5. Then again using the NuGet package manager, reinstall Microsoft.WindowsAzure.Storage which identified that it needed Microsoft.Data.OData 5.2 and installed that too.
and back to a working solution.
You can solve this issue in general whenever you update packages or add new packages via NuGet and end up with "Could Not Load file or Assembly..." issues.
Open the Package Manager Console (VS 2012 Tools/Library Package Manager/ Package Manager Console). Once the shell opens for the Package Manager Console run the command:
Add-BindingRedirect
Note: Be careful as the NugGet example added an 's' to the end in their example and Add-BindingRedirect is not a valid command.
This does the following:
Examines all assemblies in the output path for a project and adds
binding redirects to the application configuration (app.config) file
or to the web configuration (web.config) file where required.
You can see complete documentation for the Package Manager Console at: http://nuget.codeplex.com/wikipage?title=Package%20Manager%20Console%20Command%20Reference%20(v1.3)
In addition to the two entries you see in astaykov's answer the following was also added for my Project.
<dependentAssembly>
<assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" />
</dependentAssembly>
I had similar problem today. The only difference I spotted is my cloud app was looking (and failing to find) for Microsoft.Data.OData in Version=5.2.0.0
Using Visual Studio Object Browser i found out that my solution used library from that location:
C:\Program Files (x86)\Microsoft WCF Data Services\5.0\bin\.NETFramework
Microsoft.Data.OData library residing there was in ver. 5.0.0.0 so overwriting it with 5.2.0.0 resolved the problem.
P.S. I installed WCF Data Services Tools for Windows Store Apps earlier in hope of resolving this issue so it may happen that your application gets it from another source. If that is the case you have two options:
Install WCF Data Services Tools for Windows Store Apps from here and use solution above.
Use Visual Studio Object Browser to find what versions of OData library are currently visible for your project and where they are stored. Next you need to overwrite improper versions of them.
I had a similar problem as well, but I wasn't using Azure and there was no hard-coded reference that was pointing to 5.2. But it resolved (after finding this article) by making sure that the text in the .svc pointed to the correct assembly:
<%# ServiceHost Language="C#"
Factory="System.Data.Services.DataServiceHostFactory,
Microsoft.Data.Services, Version=5.6.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Service="MVC4WCFDataServiceFE5.NorthWindService" %>
Note the Version=5.6.0.0, which I didn't have before.

SQL Server Management Studio won't start

A coworker of mine has this problem, apparently after installing Re#, which seems totally irrelevant. But perhaps it isn't.
Could not load file or assembly "SqlManagerUi, Version=9.0.242.0..." or one of its dependencies. The module was expected to contain an assembly manifest. (mscorlib).
Why is this?
Thanks
I was with a similar problem, i could not open my SQL Server Management Studio.
This steps works for me:
In file C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe.config, erase the item <NgenBind_OptimizeNonGac enabled="1" />.
Example:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- ...snip... -->
<runtime>
<!-- ...snip... -->
<!-- Remove this line (~line 38) -->
<NgenBind_OptimizeNonGac enabled="1" />
<!-- ...snip... -->
</runtime>
<!-- ...snip... -->
</configuration>
I hope this helps.
Reinstalling the .Net framework didn't help me, but these next steps did. I had to completely uninstall and reinsall the shared components, but it's pretty hard to find out how to do that.
Make sure you have the installation media handy. In my case that's the unzipped folder from the downloaded SQLEXPRWT_x64_ENU ed 2014.exe
First, through your Control panel -> Uninstall a program, find 'Microsoft SQL Server 2014 (x64)'.
Right-click and select Uninstall/Change.
When you're presented with a dialog with the options to 'Add', 'Repair' or 'Remove' the product, select the last (don't worry, your SQL Server won't be touched if you follow these steps carefully.
From the initially blank drop-downlist select << Remove shared features only >>
Follow all steps from there, and you are now able to reinstall the shared features.
Management studio requires the .Net framework. Try removing/reinstalling it.
was there any installing/uninstalling of VS involved? Don't get me started on SQL 2005 and VS intall conficts.

Resources