C# Sql Server Express not Saved Permanently - c#

I am using Visual Studio C# 2008 and SQL Server Express. i got a question
i have the following data on my database
and then, i want to insert a new data
after that, i have to make sure that the entered data is saved on my database
it was there, the data was entered succesfully ! but then, when i take a look at my database table
the entered data was not saved permanently. i need to make the entered data saved permanently. how do i resolve this ?
thanks !

You are using the User Instances = true + AttachDbFileName "feature." When you use this "feature" each application you use will open a different copy of the original MDF file. So your C# app opens one copy, you insert a row, but this is never seen in the copy that is open in SSMS / Visual Studio or wherever else you might review the data.
To fix this, STOP USING THIS "FEATURE".
Create/attach your database to a proper instance of SQL Server, and point to it from your app and SSMS / Visual Studio by referencing the server and the logical database name, not the path to an MDF file.
You'll notice I called this a "feature" - in quotes - multiple times. This is because it is not a feature and has caused countless, countless users before you to become absolutely confused about why their inserts and updates "don't work"...

Related

SqlException in .updateall after convert OLEDB to SQL Server

I'm writing an app in C# with a MS Access backed (.accdb). I made the call (on advisement) that SQL Server was a much better idea for my system, thus I spent the last 8 hrs re-coding to SQL Server.
As a background;
Changed all OLEDB connection, command etc etc to Sql
Fixed all parameters and variables from ? to #value
Fixed all SQL string errors
Now all my forms are working with the exception of the ones using BINDING done by Visual Studio 'wizard' (if that's what it's called).
I have 5 forms which are filled using
this.tbljobTableAdapter.Fill(this.websterdbDataSet.tbljob);
They are all using a DataGridView depending upon that info.
On "Save and Close", this code runs:
this.Validate();
this.tbluserBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.websterdbDataSet);
_owner.PerformRefresh();
this.Close();
this.Dispose();
This works 100% still with my .ACCDB version (I'm checking from a backup) but not now that it is SQL Server.
If I press Save and Close and haven't changed ANYTHING, it closes, but if I change any field at all it fails with this (from my log):
Data Time:21/08/2017 12:12:20 AM
Exception Name:Incorrect syntax near '`'.
Event Name:System.Windows.Forms.MouseEventArgs
Control Name:BtnSave
Error Line No.:86
Form Name:frmjoblist
Any ideas how I can further debug this?
I thought it was something I did when adding Try and Catch to all my sections, but in the end this is happening to the specific 5 forms that I used the wizard instead of manually creating, binding and writing SQL update strings for.
Thanks for any advice/direction.
GAngel
So the deisgner was still all in OLEDB, therefore I ended up deleting the dataset and recreating using the correct connection which rebuilt the designer in SQL

Unrecognized database format when opening Access file inside Visual Studio - Why?

I have recently taken a project for a client which involves working with their Microsoft Access database programmatically with C# in Visual Studio 2015/2017.
The database opens in my 64-bit version of Microsoft Access 2010 just fine, and I can use/alter all tables/queries perfectly fine. However, when trying to open this .accdb database in Visual Studio, I am getting the dreaded "Unrecognized database format". Now, I do have the Microsoft Office Access database engine for 2007 and 2010 installed, and I am able to open/work with other databases created in Access.
I believe the database was created in Access 2007, as when I open it up, the title of the window contains "(Access 2007 - 2010)", so I'm not sure if that would cause the error or not?
One interesting thing I found was, because I do not need every table in the database, I copied one by one the tables I need into a new database file and checked if I could open this new Access database in Visual Studio. Out of 6 tables that I needed, the last one I needed caused the file to become "unrecognizable" inside Visual Studio.
Why? I have no idea. The table is just like any other, contains lots of columns which either have text, numbers or dates.
My question is, has anybody had a similar experience with this? Could it be the fact that it was made from Access 2007? Why would copying and pasting to a new database then cause that database to be corrupt?
Thanks a lot.
There's a difference in the formats. The older format (..2007) is MDB and the later ones (2010...) are ACCDB. If you used any features only available in ACCDB, like attachments, you cannot convert back to MDB and neither will ANY current Microsoft tool other than Access open it. Strange but true.
Painful is to exclude those tables or forms that use the new features and then do the conversion.....sigh.....

deployable database on CD

I have a Microsoft SQL database that is currently connected to a winforms C# application, it works fine on the single computer, but i would like it to be usable on a CD for any user.
I tried putting it in as a localDb but for some reason the database is duplicated and put into the bin folder, it causes multiple issues in recording data, for instances i save user ID 5 it saves in bin but never makes changes to the real database. Then next i go to create it, the user ID changes to 7 with user 6 not visible in either two databases (yes it is auto incremented by 1)
Any suggestions or best methods on making a database useable and readable via CD if the winform application is also on the CD
I have not tried this my self, but according to the documentation SQLite supports read-only databases.
If the file is read-only (due to permission bits or because it is located on read-only media like a CD-ROM) then SQLite opens the database for reading only. The entire SQL database is stored in a single file on the disk. But additional temporary files may be created during the execution of an SQL command in order to store the database rollback journal or temporary and intermediate results of a query.
see https://www.sqlite.org/c_interface.html
.NET SQLite providers are available here:
https://github.com/praeclarum/sqlite-net
http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki

how to query a database using wpf application and get output like SQL Management Studio?

I have one store procedure in my database, it makes many things and print results when i run it on sqlserver management studio (ssms), for example:
exporting table abc...
exporting table def...
deleting table temp...
My program has to run the store procedure and show the output anywhere (maybe creating a log file), such as ssms does (it shows output in the messages tab). I have to show exactly the same ssms shows. How can I do this?? sqlcmd, ado.net?? I see this question
How to run sql from a .net application against sqlserver and get output like with SQL Management Studio?
but, answer is not clear... Help!!
If you want to capture warning and information messages, you will want to create a SqlInfoMessageEventHandler delegate to handle the SqlConnection.InfoMessage event. See references below for details.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.infomessage.aspx
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlinfomessageeventhandler.aspx

How to restore a SQLite database while an open connection exists?

I am writing a plugin for a C# application which uses SQLite database. The initial database is stored in database.db.default. At any point during runtime the user should be able to reset the database to the default content.
Since the application has always an open connection to the database I can not just copy database.db.default to database.db.
Whether or not it is a good idea to always hold an open connection is a total different question. But that is just how it is since it is not my call to change that part of the application.
Is there any way I am able to restore database.db.default into database.db using C# and .NET 3.0?
I appreciate any kind of help ...
If you can't do a file copy to restore the database then do the restore the hard way. Attach the backup database, delete all the data in the main database, then insert the data from the backup database.
I'm probably missing something here, but can't you just close your connection and reopen it after the copy?

Categories

Resources