Data in SQL Server CE disappears - c#

I have a problem using a local SQL Server CE database with C# and EF.
I have a new created database file with one table and three columns. I add some data by using EF. My program, that adds the data, can read that data.
If I open the table with vs2010 the tables are empty. After that I start my program again and now there are no data too.
Anyone an idea what is going wrong here?
Bye

Go to properties of Sql CE database and set Copy To Output to "If newer"
Check ones you run the program and updates added go to $projectname$\bin\Debug or \Release and check database in there.
Reason behind this:
Default properties of Normal a database file has Build Action set to "Content" and Copy To Output option set to "Copy Always". then every time you build, your database from Visual Studio project is copied to your build or release folder and overwrites your existing database with the data added at runtime.

Related

MVC project with connection string not working for other colleagues in TFS

We are working on an MVC application, I added the connection string and generated the data models. When I update the model from database in the .edmx file it updates the web.config file and I check it in TFS. When other other people get latest version from TFS, they see the connection but when they go to the .edmx file it has update the model from database grayed out? is there any way to fix this?
First, make sure your colleagues are opening the project which in source control in VS, not the local one.
Another thing is going into the workspace and change the local path not containing '#' character. More detail info about this, please take a look at this thread: Entity Framework Unable to refresh database tables under TFS 2010

vs2015 schema compare not deploying auto generated xmlserializer assembly

I have a sql database project in visual studio 2015, that includes a clr stored procedure that calls a webservice. I have configured the projects to auto generate the serialization assembly. This means in de output folder I get both a projectname.dll and a projectname.XmlSerializers.dll.
I use the visual studio schema compare function and that works fine in comparing and updating projectname.dll but it does not show projectname.XmlSerializers.dll which I have to update by hand every time.
How do I get the schema compare to recognize and update the projectname.XmlSerializers.dll file?
In order to get SSDT to load a DLL that is not being created directly from your project into SQL Server, you need to do the following two steps:
Add the DLL to the Project (Add Existing Item)
For the properties of the newly included DLL, make sure that "Model Aware" is set to "true".

C# SQL Server CE not inserting

SqlCeConnection sqlCnn =
new SqlCeConnection(Properties.Settings.Default.mainDBConnectionString);
SqlCeCommand sqlCmd = new SqlCeCommand(
"INSERT INTO desktopItems (Location,Label) VALUES (#Location, #Label)",
sqlCnn);
sqlCnn.Open();
sqlCmd.Parameters.Add("#Location", openExe.FileName.ToString());
sqlCmd.Parameters.Add("#Label", openExe.SafeFileName.ToString());
sqlCmd.ExecuteNonQuery();
sqlCnn.Close();
I have this code but when I run the program, the database is not updating ...
Usually this scenario is caused by a simple error in visualizing the database.
Your INSERT works as expected, but you check if the insert succeded looking at a database in the wrong directory.
Using the DATADIRECTORY substitution string with a WinForms application means that, at debug time, your database is expected to be located in the directory BIN\DEBUG from your base project folder.
Visual Studio make sure that this is the case because in your project, the database file, is marked with the property Copy To The Output Directory set to Copy Always or Copy If Newer.
And it is here that the insert happens when you run your code inside a debug session of Visual Studio.
Then you check the result of the execution using the SERVER EXPLORER connection. But this connection points to the original database in the Project Folder and, of course, the new record is not present.
Usually the database in the project folder is kept up to date for the deployement, with the correct schema and initial data, but without any records that are inserted just for debug purpose.
So you could simply add a new connection to the SERVER EXPLORER pointing to the database in the BIN\DEBUG, rename it (like 'DEBUG-DB') and keep your original connection in case you need to change something in the schema of the database before releasing your application.

How to use Entity Framework with an Oracle database

I'm a starter in Oracle, I want to use Entity Framework to connect to my Oracle database.
I first installed Oracle 11g R2 and get this and then I install NetManager and create new Service Name
Then, I go to Visual Studio and create a new model but wWhen I want to create a connection it gives me an error message.
Please help me. thanks all
It had happened me once. In your Oracle home directory there must be two folder in directory C or D:\app\user\product\11.2.0:
Names of folder must be smth like that:
client_1 and dbhome_1
There must be tnsnames.ora in \client_1\Network\Admin\Sample. If not, create one. Then first of all delete all texts in this file and copy this to that file:
orcl=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.77.31)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))
Instead orcl you will write your data Source. Also for host and port number. And Service name.
It must work. If not copy tnsnames.ora and listener.ora to \client_1\Network\Admin.
And test it again.

Setup a test environment on my local machine using Visual Studio

What is the easiest way to setup a test environment on my local machine using Visual Studio 2008 with a website that that has a mssql database, which is hosted through a webhost?
I am web designer and I am re-skinning a live website that is built in .NET C#. I have access to the files and when I run it in Visual Studio (localhost) only the static files are obviously pulling up , which is problematic for testing. I need to be able to run the entire website on my local. I am not going to be messing with the database at all, but I know that I am going to need it to be able to have a local copy that works. I am not extremely savvy on these types of things. I was hoping that someone could either point me in the right direction (ie. search terms, keywords) or give me some instructions on how to make this work. Any help is appreciated.
Thanks.
You should set up MSSQL server first. You can take backup from your production database using
RMC on DB -> Tasks -> Backup..
Then you use the generated .bak file on your local server to insert the copy of the database into your SQL Server instance like this:
RMC on Databases -> Restore Database -> Path to your backup..
At this step your instance should contain the database with all the tables and data. Next thing to do would be to change your web.config file connection string (or any place else, where the "Connection string" is set pointing the website to the database) accordingly to your instance. If it's MSSQLSERVER instance name, you can just use following connection string:
Data Source=(local);Initial Catalog=<database name>;Integrated Security=True;
After this compiling and running your source codes should be returning you the site in its fullest.

Categories

Resources