Where did Entity Framework 6.1 put my database? - entity-framework

I am using EF 6.1 and VS 2012 to create a Code First data model basically following the Code First module in Julie Lehrman's EF5 Pluralsight video. It appears to be working just as advertised except I can't find the data file anywhere. I can access it in code, but by no other method.
I am using the LocalDb default connection factory. The database does not appear in the Sql Server Object Explorer under (localdb)v/11.0. There is no mdf file anywhere in the solution or my user folder. Where did Entity Framework put the data?

Maybe looking at the connection string in the debugger will help you find it. Take a look at the Database.Connection.ConnectionString property of the Context you new up.
EF generates a different default connection string depending on the context it's ran in, so I can't tell you for sure where it'll be.
The relevant source code for generating the localdb connection string is here

LocalDb databases have a default location (C:\Users\xxxx\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\v11.0), and you can open MSSQL Management Studio against them with the connection string "(localdb)\v11.0" and Windows authentication.
See http://blogs.msdn.com/b/sqlexpress/archive/2011/10/28/localdb-where-is-my-database.aspx

Related

IdentityServer4 entity framework SQL Server connection string

I am trying to follow quickstart to setup SQL Server (not LocalDb version of SQLServer that comes with Visual Studio) as my data store. Looks like that two databases will be needed - one for configuration and the other for operation. But my problem is that I couldn't figure out what db names I should use. I created two databases using names I came up with and ran the scripts I downloaded from quickstart to create all the tables. Now, when I try to make connection, I think I will need to specify db names in my connection string, don't I? What should I use to replace the original connection string provide by quickstart - "Data Source=(LocalDb)\MSSQLLocalDB;database=IdentityServer4.Quickstart.EntityFramework-4.0.0;trusted_connection=yes;" ?
You can have one database for both. But in general I would keep the configuration part in memory if the number of clients is small. Why spend hours keeping the config in a database for just a few clients and resources?
Better to just keep the users and persisted grants in a database.

Connection error when trying to create entity model from SAP HANA DB

I am trying to build a ADO.NET entity model from a SAP HANA database. This is for SAP B1. This process is pretty straight forward using MS Server/MySql etc.
However, when I follow the steps of creating this HANA model, I get the following error below on clicking "Test Connection":
general error: database 'EOH_CCL_TEST' does not exist
I have added a reference for Sap.Data.Hana.v4.5.dll.
Version is 1.0.120.0.
The database exists and I am able to perform queries on it as can be seen below.
Note: I am using the same credentials as I used to log into SAP HANA Studio.
What am I missing here?
There is a previous post: ADO.NET Provider for SAP HANA - Version mismatch issue
But in that issue, the user was able to make the connection.
You are using the schema name EOH_CCL_TEST as database name. The database name is different to the schema name. Did you logon to the SYSTEMDB database or to a tenant database in HANA Studio? Using the used DB name should solve the issue for you. PS: I also do not think that you need to add a port in the hostname property field.
Going from the screenshot you are not using a HANA system with multiple database containers. In this “classic” setup there is no separate admin object “database” and connections don’t take a database name.
Just put in hostname and port and leave the database name empty. The EOH_CCL_TEST is indeed just the schema name.
Beyond that, it’s really not a good idea to use SYSTEM user for working with data or really anything beyond bootstrapping the system.

Enabling mdf location to be accessible in management studio and easy to create when distributing the application

I am using Entity Framework Code First to create my database.
Here is the current connection string
"Integrated Security=SSPI;MultipleActiveResultSets=True;Pooling=false;Data Source=(localdb)\\v11.0;Initial Catalog=Inventory"
However this database is not visible when I try to attach it inside SQL Server Management Studio.
This is because the account that runs the SQL Server service would need to have access to my user folder in order to see it.
I tried giving this account access but had problems due to permissions of other things in my user folder.
Thus I thought I should perhaps specify a folder name for the database to be created in, but I am unsure on how to do this, and what other problems this approach may bring.
[Update]
I am now investigating setting the AttachDbFilename in app.config
this link is helpful however I aren't clear on how to set up |DataDirectory| for a winforms app.
[Update]
The following connection string works
<add name="ConnectionString" connectionString="Integrated Security=SSPI;MultipleActiveResultSets=True;Pooling=false;Data Source=(localdb)\v11.0;AttachDbFilename=c:\databases\MyDatabase.mdf;"/>
It would be helpful to know how to configure the path to be the same as the exe file location.
You may first use sql server management studio (ssms) to connect to your localdb instance (server name: (localdb)\v11.0, Windows authentication)
make a backup of your localdb database (right click db -> task -> backup)
then share the db backup file with other system.
I wound up placing the following in Main()
AppDomain.CurrentDomain.SetData("DataDirectory", AppDomain.CurrentDomain.BaseDirectory);
and the following in app.config
<add name="ConnectionString" connectionString="Integrated Security=SSPI;MultipleActiveResultSets=True;Pooling=false;Data Source=(localdb)\v11.0;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;"/>

SQL Service Broker creating objects in SQL Server Database Project in VS 2012

So I've started a SQL Server database project inside VS 2012. I have done this for other databases already but not related to Service Broker.
For testing I had already created db, queues, etc through a T-SQL script including Message Types which was in an XML format. i.e.
[//blah.com/Items/RequestItem]
When I try to do something like this in the DB Project it's not allowing me too due to special chars.
Anyone done this? Gotten around it?
Is there a way to simply put my already created T-SQL file in the database project and have it use it?
See my comment above. I was able to import the script by Right clicking on the database Project.

Issue with ADO.NET plus SQL Server Compact 3.5 database

I'm now using SQL Server Compact 3.5 as my local database (in order to make it compatible and running on PCs without SQL Server installed). And I tried to use ADO.NET and Entity Framework to write connection services. However, I found some issues, for example I was trying to save a new object, it looks succeed, but it's actually not really going into the database. I feel it's like just storing in memory or something (when I re-run the project, the data is still there but it's not in the database).
My environment is: SQL Server Compact Edition 3.5 + Visual Studio 2010.
EF code should be correct and is quite simple:
using(TestEntities te = new TestEntities()) {
SystemUser su = new SystemUser();
su.id = 1;
su.name = "123";
te.AddToSystemUsers(su);
te.SaveChanges();
}
I used the same code but with the database in SQL Server Management Tools, it works fine.
Can someone help me explaining with this? Is there any ways to solve the problem?
Big thanks in advance!
You have included the database file as content, and each time you debug, it is copied to the bin/debug folder. To solve this, I recommend using a full path in your connection string.