Problems using SQL Server CE - c#

I am using a SQL Server Compact database for a project I am working on and have been having a hard time trying to insert data to the database.
My insert statement and everything is working fine and data gets inserted too and I can even do searches for the inserted data (while in the application).
The problem I am having is when I quit and re-run the application, it seems that the data was not inserted into the database and the tables are empty too.
Can anyone let me know where I am going wrong with this?
Thanks

Could it be that the SDF file is overwritten with an empty version whenever you rebuild/run the application?

As Thorsten pointed out, check the Build Action on your SDF file.

Related

Failed to update database with SqlCommand and also with DB Entity in C#

I have made a program with a simple SQL Server .mdf database file.
First: I have connected to the database using SqlConnection and tried to insert some data using SqlCommand. The ExecuteNonQuery returns the number of affected rows successfully for example 1 or 2 ... etc.
But when I use Server Explorer to view the data of the table, there is nothing inserted!?
Then I have used model entity object and DataSource. On SaveChanges function I get also the number of affected rows successfully, but there is no data inserted in Table on viewing it.
When I make a query using Server Explorer, the data will be inserted successfully and I can view it!!? Can you please help me to solve this problem?
thank you marc_s, you gave me a hint "ConnectionString". As I created a database mdf with server explorer, I realized now, there is two mdf files created. One is located in base folder of project and the other located in bin/debug folder. I don't why there is two of them, howerver it solved my problem. Thanks

c# Tableadapter fails to update through odbc

I have a complicated issue to solve.
Basically i have a winform application which uses datasets and access files to save data.
Now i have a customer which would like to have the database stored on a sql server.
So .. i made the database in sql and an mdb file with odbc tables attached to it.
And here is the issue.. The program works only in reading and inserting new data. When the user tries to update an existing row the tableadapter goes in concurrency exception.
I can't really understand the reason or how to solve this.
Anybody got any idea or any tips about this issue?
Thank you!

SQL table getting deleted by itself in local db, using LINQ to SQL [duplicate]

I'm making a WinForms app in C#. When I go to create my database object, I'm presented with two options:
Local Database
Service-based Database
All I want is a simple local database to use for my project.
However, if I select "Local Database (Compact Edition)" then after I create my tables and drag them over to a LINQ-To-SQL Class creator it says:
The selected object(s) use an unsupported data provider.
So, I don't know why creating a local database would be considered an unsupported provider when dragging to tables to the Object Relational designer.
So, I try the second type, "Service-based Database". I lay out my tables how I want for my basic application and make my tables. The LINQ-To-SQL Designer works fine when I drag these tables and I proceed to write my code in my app to insert and upate the database entries.
However, with this second "Service-based Database" my inserts and updates work as long as the application is running. However, once I close it it reverts back to what it was before. If I manually add in data via the Server Explorer it persists but any inserts I do don't save.
Why can't I create and use a Local Database with LINQ?
If that isn't an option, then why isn't the "Service-Based Database" (whatever that is), persisting beyond the application closing?
Thanks for your time!
Edit: Apparently the LINQ-To-SQL Object Designer doesn't work on Compact Edition Local Databases. It can still be done, but you have to use SqlMetal apparently to generate the dmbl file.
When you compile, the old database gets erased and a new one is copied to the bin folder. Therefore try link (using linq) to the database in the bin folder. Try change your connectionString.

MySQL trouble with the strings.How to convert to utf8?

I am having the following problem. I am creating a C# windows Forms application with which i want to transfer the data from a SQL Server to MySQL. The problem is that the data in the SQL is in latin and when i trasfer it in the MySQL DB it is shown like "?". Please give me some advice. I have tried to convet it but it does not work!
thanks in advance!
How are you selecting the data - using a sproc or sql command?
You can put a collate in the query (see : MySql Manual Ref) and force the correct collation back to your app (if reading from MySql or MS SQL both support it). This is easier than trying to convert (which does not always work as character sets are different sizes) or changing the db charset/collation.

Not getting database table updated

I am simply writing an INSERT query to insert values into the table, when I click the submit button the code runs successfully, I don't get any error.
But when I look into the table it shows no data i.e the table is not updated. I don't know why it's happening. Can anyone suggest me.
thank you
I had the same problem if you are using c# windows application probably you have two different data base connection one updated and another still not updated so check your connections and if you are using sql express your database might be replicated in you debug directory so check your debuge folder or run your application from executable file.

Categories

Resources