My Program uses EF to access data from a SQL CE database. When debug the application using debug setup it works fine but if I use release setup I get a MetadataException when the program tries to access the database through EF.
What I've checked so far:
Debug and release configuration is identical (same target platform)
The app.config is copied to the same directory as the executable (\Release)
The sdf database file is copied to \Release\
Metadata Artifact Processing is set to Embed in Output Assembly
Connection string name is identical in app.config and EF model
My app.config:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="GeoDataEntities" connectionString="metadata=res://*/Model.EF.Model.csdl|res://*/Model.EF.Model.ssdl|res://*/Model.EF.Model.msl;provider=System.Data.SqlServerCe.3.5;provider connection string="Data Source=|DataDirectory|\GeoData.sdf"" providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
The assembly Model.EF is the namespace and Model the name of the edmx, I think that should be right.
I know that there a lot of posts and blogs about MetadataException and I've tried to solve this but nothing have worked so far.
Best regards
Jay
I really don't know what I've done but it's working since I've checked in and checked out from TFS.
Related
I am new in c# programming. Recently i developed a desktop app and create exe file for this. But it is not run in another pc. Here my app.config file-
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="newConnectionString"
connectionString="Data Source=.\SqlExpress;AttachDbFilename=|DataDirectory|Asset_Management_System.mdf; Integrated Security=True;User Instance =True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Please help me.
Build the project in a release state (Build>Configuration Manager> Active Solution configuration). It is going to create a Release Folder inside the "BIN" folder, which would contain all the files need to execute the program. If you make reference to others files, they should be contained there too, so put them on that folder. This folder can be carried to others PC running windows with ".NET Framework" installed and the application should run fine. Also, you can create an installer by deployment technologies like Click Once, that would do stuff like Install all the dependencies automatically (.Net Framework, visual C++ etc.) and special configuration or settings.
I am using WebDriver and NUnit to create tests in C#. Is there a way to specify at runtime the URL and the Browser without having to change the code and rebuild?
Basically can I run the same tests against different URLs (Dev, QA , UAT etc) and different Browsers without having to recomplile.
Many Thanks.
After much searching I eventually came up with the solution by combining the best bits of two other incomplete solutions.
Config file should be the same name as your test file dll eg TestFile.dll.config and located in the same folder.
This is the format of your config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="TestURL" value="http://www.example.com/"/>
<add key="Browser" value="Firefox"/>
</appSettings>
</configuration>
Add a reference and a using statement for System.Configuration and use code like this to access your parameters:
testURL = ConfigurationManager.AppSettings["TestURL"];
browser = ConfigurationManager.AppSettings["Browser"];
All improvements, suggestions and comments are welcome.
We're building a .NET 4 WPF application that runs from a network drive. The application starts fine for me and most of my (developer) peers.
Recently, a software tester has joined our development team and was put in the same AD groups as I'm in.
Whenever he launches the application, this dialog pops up:
and the app naturally crashes after that.
When attaching a debugger, the debugger breaks at the first line of EF 4.4's DbContext constructor, for which the code is as follows:
public class CardioDanosContext : DbContext
{
// ...
public CardioDanosContext()
: base("CardioDanos")
{
// Irrelevant first line
As you can see, we call the DbContext's constructor with a connection string name which is defined in our app.config like so:
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- ... -->
</configSections>
<runtime>
<loadFromRemoteSources enabled="true"/>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="External;Resources;Base;Services;Modules;Data;"/>
</assemblyBinding>
</runtime>
<connectionStrings>
<add name="CardioDanos"
connectionString="Data Source={snip};Initial Catalog=CardioDanos;Integrated Security=True;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<appSettings>
<!-- ... -->
</appSettings>
<!-- ... -->
</configuration>
Now, I'm assuming it is an issue with permissions, but we've verified all permissions for the affected user and they all seem in order. He can read and modify the app.config file without problems. I also assume it has something to do with running it from a network drive, but then again, it works fine for some of us.
I've not really found anything about this while searching the Internet, but does anyone have a clue why this could be happening?
Some googling tells me that some assemblies cannot be loaded. Are you sure that everything is correctly installed on the client? Any third party assemblies you are using that are installed in the GAC on your development machines, which are missing on the clients machine?
How are you deploying the application? Are you creating a publish, or are you just copying the bin/debug folder? If the last, then you are not including any specific referenced assemblies if you have not set 'Copy local' to True.
How is Entity Framework referenced? Are you using a NuGet package, or an old install which you have done manually?
In my windows form i have connection string in app.config as
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Database"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database.accdb"
providerName="System.Data.OleDb" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
And in all classes i am using the following code to connect to the database.
string connString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString;
But its not connected to the database.
Can somebody point out the mistake.
But when i use this code without use of app.config it works fine.
string connString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source = C:\\Users\\Amrit\\Desktop\\Database.accdb; Persist Security Info = False;";
How can i make the app.config connection string work..
You may do it so
<configuration>
<appSettings>
<add key="ApplicationTitle" value="Sample Console Application" />
<add key="ConnectionString"
value="Server=localhost;Database=Northwind;Integrated
Security=false;User Id=sa;Password=;" />
</appSettings>
then use ConfigurationSettings.AppSettings["ConnectionString"];
It seams (from the comments) that you are targeting two difference database files in those two connection strings. The first one is in your App_Data folder of your project, and the second one resides on your desktop.
The file in your App_Data folder is copied in to the output folder (bin/Debug or bin/Release for a WinForms project) every time you start the project in the VS. It overwrites previous contents of the file so every time you have a fresh copy of the file form the App_Data folder in your output folder. To find out, run the program and execute a few insertions. Then close the program and open the database file in the output folder (not in projects App_Data).
This happens because you have set the Copy to Output Directory property of the database file to Copy always.
you need to set DataDirectory.
You can then set the path in Application_Start in your Global.ascx.cs
AppDomain.CurrentDomain.SetData("DataDirectory", "C:\Users\Amrit\Desktop");
https://stackoverflow.com/a/1409378/2745294
https://stackoverflow.com/a/6708279/2745294
Hope this helps.
this is my app.config file. I am using vs 2012 with c#.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="Small_Business_Management.Properties.Settings.businessdataConnectionString1"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\businessdata.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
now i included the database file businessdat.mdf in the solution.Now when i publish the application it is not working in other computers.It works fine in mine. In other computers it asks me to install sql server.How can i publish with a local database so that it works without installing sql server in other computers
If you want to use the LocalDB functionality of SQL Server 2012 you need to install the LocalDB functionality on each device you deploy to. You can find the installer here.
It is possible to do a silent install, so you can include it in your application installer if you have one:
msiexec /i SqlLocalDB2012.msi /qn IACCEPTSQLLOCALDBLICENSETERMS=YES
more information here and here
If you really do not want to (or can not) install anything on the devices you deploy to, you can always check out sqlite
You basically have two choices:
Install LocalDB on the other computers - you may be able to integrate this into your installation/deployment process for the app.
Use an embedded database
To expand the above a bit, to avoid an installation you'll have to use an embedded database so that the necessary libraries are deployed with your application. In context the obvious choice would be SQL Server Compact which should work with the code and SQL you already have i.e. there's a reasonable chance you'll only need to add the files/references and change the connection string.