How can I see sdf file - asp.net-mvc-3

I am using mvc3 to develop an database application and followed the Code-First Tutorial using Entity Framework 4 of msdn site....
I followed all the steps but unable to see the sdf file....
I can perform CRUD operations but can not see the physical database file inside the app_data folder
I also did "Show all file" but still it is not shown in my visual studio explorer...even my App_data folder is empty...
Code inside the web.config file:
<add name="Forum1Context"
connectionString="Data Source=|DataDirectory|\Forum.sdf"
providerName="System.Data.SqlServerCe4.0"/>
Please Help me!!

I experienced a similar issue. In my case, the name attribute in the add tag was not the same as the name of the class which inherited from DbContext. When I changed the name attribute to match, then I could see the .sdf file, but rows I had inserted previously into the database were lost.

It could be that the Database considered your SQL Express rather then the connection string. Fire up SQL Management Studio and check your SQL Express server

"Data Source=|DataDirectory|Forum.sdf" means Database file is located at "App_Data" folder.
And if you can even perform CRUD operation, Database file should be already there as "App_Data\Forum.sdf". (Please also verify with window explorer).
On Visual Studio, need to enable "Show All Files" on Solution Explorer to view Database file.

Just wanna point out that SQL Express and SqlServer CE are different. SQL Express will need a memory pipe or TCP connection like any other DB server, and the Sql Server CE will automatically create your DB file if doesn't exist at first runtime.
Could it be that you haven't run our app (and EF4.1 code) hence your .sdf file isn't there yet?

Just remove the backslash \ before Forum. I think that will solve it.

Related

VBOLEDB data connection not recognizing all the .DBF files

I'm using Visual Studio 2013 and I'm trying to import some .DBF database files into a dataset. I'm using the OLE DB FoxPro Data Source Provider and it does work, it just will not load all the .DBF files using the Data Connection so that I can choose which files to add as tables in my dataset. It's as if it doesn't even see them. I cannot use an ODBC connection because it crashes Visual Studios every single time for whatever reason. However, when I add it as an ODBC connection, it does recognize all the files like it is supposed to. I just can't use them or it will crash. I've been working on this for days, so please help! It will not allow me to add these files using the Microsoft Jet 4.0 either.
Without seeing your connection string, I can only suggest posting it. However, I would also preemptively guess that your connection string is pointing to a specific .DBF file which connects to a single table.
Your connection should point to the LOGICAL DRIVE / PATH and not explicitly name a .dbf file.
The other possibility is that if the files are part of a database CONTAINER (via .DBC file extension), then you should be able to query and table in the database container.
What MAY be failing is if the table is part of a database container, and it has long column names beyond the 10 characters of the older / free-form table formats, that MIGHT be preventing querying for that reason.
Let's see your connection information as best as you can without any possible id/password information.

Attached SQL Express DB is causing problems

I have been asked to create an MVC web application in VS 2010, and was instructed to use a SQL express database for my data. I am using EF Code-First for creating and managing my data. The database was created in VS2010, and is attached via "AttachDBFilename" in the web.config.
I have used SQL CE before with MVC with no problems, however the attached SQL Express DB is causing weird issues.
For one thing, when I try to deploy the app, it fails and tells me that it cannot copy the database.mdf because it is in use by another process. I have NOT opened the database in VS2010 nor SSMS. Of course the program code accesses it - is there some reason that connection would remain open? I am using boilerplate code from the scaffolding.
I should mention that I use a ProjectInitializer.cs to create the sample data. It runs at every launch for the moment, since I am testing quite a bit.
The other problem I have is that if I delete the database, it fails to recreate it. It says that my windows account does not have access to the (now non-existent) database that it is trying to create. I literally have to create a new database with new name, as anything that was created previously (with that DB name) fails.
I assume there is some sort of residual info being left somewhere that is out of synch, but I don't know what it is. I've closed all connections to the file in VS 2010, deleted the files, both any found via VS2010 and any physical files I see in the app_data directory.
Any help or suggestions would be appreciated.
Shut down the web server (Cassini, IIS, IIS Express) and try again. The file can remain locked if the web process is still referencing the file. In addition the loaded EF context will retain the db name. Ensure the visual studio browser isn't running in the tray still either.

MVC Code First: App_Data Folder Not Being Created

I'm using the MVC Code First approach to create a SQL Compact database (from WebConfig: data source=|DataDirectory|MailBoxDB.sdf). The .sdf file should get created automatically, and it does if I manually create the App_Data folder on the web server (Windows Server 2008). However, I'm trying to automate the deployment process and I want to eliminate this manual step. I'm using MSDeploy to create the deployment package. Is it a permissions issue that prevents IIS (7.5) from creating the App_Data folder on its own? If so, which settings should I be focusing on? Any ideas?
I had a similar scenario (generally more complex, although without a database in App_Data). I pieced together several SO questions and found a solution which I've posted on my question on the same topic. Take a look at my answer and hopefully it helps.

cannot save record in attached .mdf file with EF 4.0

I want to create a VS 2010 project with EF 4.0 model.
But I have no records and errors after inserting new record with attached .mdf file .
But if the base is connected to Sql Server, it works fine.
Please help me to insert records to attached .mdf db
You need to make sure DB is not in a shared folder, is on your pc, is not read only, that you have write permissions to the folder that contains it and there is no DB already attached to service with same name. Make sure you can connect with Server Explorer window first.
Consider using SQL Server CE, if you want to work with loose DB files.
Also, make sure the file is not overwritten with each build. (Use "Copy if newer", not "Copy always".)

Visual Studio and an Access Database - Operation must use an updateable query

I am deploying an .accdb file to the same directory as my windows forms program is being installed. However when attempting to update data in the database i get a "Operation must use an updateable query" error.
The file attributes are not read only, however when I open the accdb file it stats that the database has been opened read only. I must save a copy to make it not read only.
I do not believe this has anything to do with permissions, or file attributes. This is only on Vista, XP appears to work ok. The original accdb file is not read only when i open it.
What is visual studio doing to the accdb file to make it read only? and how can i fix it.
Are you installing into the Program Files heierarchy? If so that's read only for users and would cause the Access database to be read only. You should be installed any Access database file to the users Application Data folder.

Resources