How to embed a database to a WPF application?
scenario: this is our school project and we are required to create a
system with a database. now, i have done the fundamentals (create a
database, creating a layout and the c# code for programability) but
now, when we are to transfer the build onto a different computer, the
database seems to be lost.
I'm using Visual Studio 2015 with SQL Server for its database and that database is placed within the localdb of my computer. what i want is a portable system so that we can present the system anywhere without the hassle of bringing my desktop to school.
thanks in advance <3
EDIT: there are a ton of ways to connect a database to a wpf
application and i dont know what to choose. theres the ling-to-sql,
entity framework, data source etc. which of these methods will be the
best way for a portable application with the database in it.
my WPF app uses SQL Compact + Entity Framework (code first) + migrations, yo can find sources here https://github.com/tym32167/arma3beclient
All database-related things placed in this project https://github.com/tym32167/arma3beclient/tree/master/src/Arma3BE.Client.Libs
Data context here https://github.com/tym32167/arma3beclient/blob/master/src/Arma3BE.Client.Libs/Context/Arma3BEClientContext.cs
Migrations here https://github.com/tym32167/arma3beclient/tree/master/src/Arma3BE.Client.Libs/Migrations
Related
I am writing a console application using .NET 5, and I am using a LocalDB instance (at least I hope that's the right terminology) to store the data that the application needs. I can see the database (including both tables and all the data in said tables) in both the Server Explorer and SQL Server Object Explorer tabs of Visual Studio 2019, but the Data Sources tab the only thing that shows is the text "This window is not supported for the selected project."
The problem is, all the tutorials I've been able to find rely on that Data Sources tab. From looking at other questions here on Stack Overflow, it looks to me like that tab is deprecated with .NET 5? Am I correct? And how would I write the code to access the database and perform CRUD operations without the Data Sources tab?
Sorry if this is a stupid question; this is my first time using LocalDB.
You should use SQL Server Object Explorer. If you right click on the database that you want to connect, you can see the properties, including connection string. If you have trouble with incorporating Connection string into your code - you need to show the code and the problem.
Whether Data Sources is deprecated or not, as you can see it is not supported for most projects (I think it's just for Windows projects - but I may be wrong). Anyway - you don't need it. And by the way - this approach works regardless of the database you use (LocalDB, SQL Express or regular SQL Server)
I am planning to create a windows forms application with standalone database.
When i tried to add a new database item in Visual Studio i can see a Dataset and Service-based Database. Could you please let me know which one should i use or is there any other db i can use.
You can use sqlite.net:
https://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki
It is pretty straight forward to use. You need to add the appropriate DLLs to your project.
I'm busy writing a small app and I only want a database to load small amounts of data, in other words I don't need the functionality of SQL.
So I've installed filehelpers, but it seems very limited in the sense that I can read/write and even append data, but it seem impossible to delete one row of data in a table?
Does anyone know how to do this with filehelpers or point me to a different solution where I can just add a local db to my app without any other external software required?
PS. My visual studio does not have the "create local db" from the item selection.
For something like this, I'd use an embedded SQLite database. It gives you the best of both worlds, one file database for local data and most of the features of SQL.
See here: https://sqlite.org/
On their download page, they have lots of stuff and a plugin for VS:
https://sqlite.org/download.html
I am developing an application in SQL Server using C#.
My database version is SQL Server 2005 Express edition, and .Net framework 2.0.
I want to make an updatable application.
e.g. whenever I do some changes in my application, then it should be available to update in all locations (like update in Mozilla Firefox).
But I also want that if I change some columns/stored procedures of the database, then those changes should be also updatable.
Please guide me how can I make that kind of setup.
Do you have any server or network share where you can distribute your application from?
If so, then you should take a look at ClickOnce which is available in any version of visual studio. it will automatically update the client each time you publish a new version. http://msdn.microsoft.com/en-us/library/t71a733d%28v=vs.80%29.aspx
As for the SQL updates, I'm not sure what you're asking for? if you use one database for many clients, then the only thing you will have to update is the client code which works with the database. in which case you will do the same thing as with any client update.
If you're having multiple instances of the database, you'll have to update each of them manually. You'll really want to keep track of each change you've made or use a comparsion tool for that. I'm using Red Gate SQL Compare, but I assume that there are also free tools.
First you need to decide on a setup tool which will create an EXE or MSI installer for your application. Perhaps this list will help: http://en.wikipedia.org/wiki/List_of_installation_software
After that, you can integrate an updater application into that installer. Here is a post with more details: What is the best way to auto update a windows application?
An installer takes care of the distribution and the updater takes care of your application updates.
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.