Can't get Entity Framework to connect - entity-framework

I'm getting the following error:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
I've just created my first ever EF project. It's an MVC app and I added the entity model in the MVC project. I also added a DataAccess class and a class for running tests using NUnit. Eventually, I'll add a service class which will reference the DataAccess class. So, the code currently looks like this (I'm just trying to get a test working to prove EF is doing its thing):
Text Fixture calls DataAccess class
DataAccess class calls Entity Framework
Entity Framework accesses a local database
For the time being, I'm just trying to return all rows/one column from one table. Remember, all these files are in a single project. I've read quite a lot that this problem stems from having multiple projects, but that doesn't seem to apply in my case. I've checked in the "main" web.config file. The connection string looks okay. I copied that same config section (i.e., connectionStrings) into the Debug-specific config file, too, but that didn't make a difference. Any ideas why I'm seeing this error?
Thanks,
Jay
Connection strings:
This is the connection string from the dialog box when creating the Entity Access file (data source is a period in both strings [i.e., local host]):
metadata=res:///EntityDataModel.csdl|res:///EntityDataModel.ssdl|res://*/EntityDataModel.msl;provider=System.Data.SqlClient;provider
connection string="Data Source=.;Initial Catalog=URIntake;Integrated
Security=True"
This is the connection string from the web.config file. They seem the same, for all practical purposes:
metadata=res:///EntityDataModel.csdl|res:///EntityDataModel.ssdl|res://*/EntityDataModel.msl;provider=System.Data.SqlClient;provider
connection string="data source=.;initial
catalog=URIntake;integrated
security=True;multipleactiveresultsets=True;App=EntityFramework"

Microsoft Zlatko Michailov Says,
app.config is not in the binary directory where the exe is. Please do
the following:
Visually verify that the app.config with the expected content is in the directory where the exe is compiled. (Existence in the project
root directory is not enough.)
Use System.Configuration.ConfigurationManager from within your app to examine the content of the app.config your exe is using.
I’m also looking at the content of the connection string, and I can say
that it may not work in a multi project environment (unless you’ve
duplicated the EDM in each project).
The reason for that is “.”
resolves to the directory where the exe is loaded from. If you want to
reuse the same EDM, you at least have to make a few steps back in the
path and then navigate to the project where the EDM is, e.g.
“......\Proj1\AdventureWorksModel”.
Additionally you may consider
using the |DataDirectory| macro - when you load an AppDomain you can
set |DataDirectory| to point to the exact directory where the EDM is,
and then use that in the connection string, e.g.
“|DataDirectory|\AdventureWorksModel”.
If you are working on an
ASP.NET project, you can use “~” which refers to the project root. In
that latter case, you can’t reference a model outside your project’s
hierarchy though.
For more information Check Here
UPDATE 1 :
Here you can try below mentioned steps
Clear connection string content on the web.config file like below
Then Remove your *.edmx file from your project
Recreate it again like below (sample one).Don't forget to tick the "save entity conncetion settings in web.config as :"
Final Step : After that go to the web.config file and check whether your connection string is exactly the same as on which showed on "Entity Connection String :" as above step(I showed it on red mark above image).
I hope this will help to you.

Related

Blazer Server App - Add web.config settings

I have a Blazor Server app that is running under IIS. I see that it generates a web.config file upon publish with some settings in it.
I need to add some more settings to the web.config as they are used by another component (asp.net 4 app). Does anyone know which file I need to create/modify in order to be able to add these values.
At this stage I do not need to use transforms on the web.config, but it would be nice to know this as well.
What I found is that the web.config works as per Asp.Net Core documentation. In brief for a Blazor server app hosted under IIS (this is my understanding)
If there is no web.config existing in the root of the project directory, one is created during the build and copied to the bin directory. It will contain default information.
If a web.config exists in the root of the project directory, it is copied to the bin folder unmodified (note: it requires some default settings inside).
If transforms exist, they will be applied.
I didn't realise that the web.config is created if it did not exist hence my original question.
Also, I have not been able to get transforms to work yet.
I found that if you publish the project the web.config in the root gets ignored and uses the auto-generated one.
Adding this to my blazor project file solved it and can see the web.config getting published to Azure now:
<PropertyGroup>
<PublishIISAssets>true</PublishIISAssets>

revEng command in Entity Framework 7 creates file in the project root

I am kicking the tires with EF 7, specifically the revEng command.
I have been able to run the revEng command and get the context and POCO files generated.
However there are two things I would like to tweak:
The context and POCO files are created in the project root.
The database connection string is hard coded on the context file.
Is there a way to move the file to another folder from the command? In other words, a Models folder? I could move the files manually, but doing that each time I update the model sounds like it would get old.
Is there a way to have the generated context file reference a connection string from the config.json?
If what I ask is not available, is it in the backlog, and this just life in preview land?
The abibilty to specify a project folder will be available in beta 8 https://github.com/aspnet/EntityFramework/commit/5b19fbbff82987ba9e1aafe051ff8c4fd02bf8cf

EF 4.3 migrations throwing "Unable to open configSource file"

I'm trying to use EF 4.3 migrations feature. My ASP.NET MVC project stores connection strings in external file:
<connectionStrings configSource="bin\connections.config" />
All runtime procedures (including automatic migrations) work fine. However, no powershell commandlet, connecting to the database, is able to find external file. It throws "Unable to open configSource file" exception. I was trying to place .config file in different places as well as changing configured external file location to no avail. Is there any workaround available?
Update: I've found that EF creates a temporary AppDomain with configuration file located in temp directory. So the only workaround at the moment, it seems, is to place external configuration in the same temp directory. Any other suggestions?
Using EF 6.1 here.
If like me you were linking to a connectionStrings.config file located in another project than your Entity Framework migrations project (using Add as link), you'll probably need to move the file back to this EF project and link to the moved file from the other projects instead...
There are unfortunately no easy way to handle external configSource files with the powershell cmd-lets in EF migrations. I've given up on it and moved the connection strings into the config file for the class library that contains the db code. The alternative is, as you've found out yourself to manually copy the file. Unfortunately the copy process doesn't honor the build settings of the project, so setting the external config file to be copied at build doesn't help.
EF 4.3.1 supports configSource.

packaging and deploying java desktop application with embedded database

I created a simple desktop application that uses embedded database(derby) from netbeans.After adding two entries into the table inside the ide and running it again works perfect.But when i double click the executable jar file outside the ide an empty database is shown what might be the reason? I would also like to know how to make this run on client machine.I tried adding the jar and lib files into a folder and converting it into a rar file but i don't find the jar file after extracting.I am new to this and any help would be appreciated.thanks in advance
There are two common reasons why you find that you are getting an empty database unexpectedly:
You are saying ';create=true' and using a relative database name, meaning that you are giving Derby permission to create the database fresh if it doesn't exist, and then your Derby system home directory is changing from run to run, so you are ending up creating new copies of the database each time, in different current directories.
You are using a different username when you connect to the database. Since the username with which you connect implicitly specifies the schema in which your tables reside, using a different username causes you to see a whole different set of tables, or, depending on how you look at it, an empty database.
Regarding jars and rars and such, the crucial thing is to manage your CLASSPATH properly. You need to have the Derby code in your CLASSPATH at runtime. There are a large variety of ways to make this happen, so you'll need to be quite explicit about the particulars of your situation in order for others to give you much help.

entity framework client connection details versus connection details in EF library?

I have an EF project which has embedded connection details.
Then when I use this project from a client library I get told to copy the config file across, which includes the connection details.
What are the rules re which connection string would be used here? i.e. does the database connection string in the client project override any connection strings in the EF library project?
The connection strings in the library project are never used, they aren't in the bin folder with your final executable. Only the connections strings you copy over to the application or web config files (as appropriate) are used.
But don't copy the whole config file over - you want just the connection strings.