Change Include Database In Project Setting After Creating Dataset - c#

When you create a dataset, you get the option of including the database file in your project, instead of the connection string pointing to the database file in the sql server data folder. My question is, is you select no, how can you later, after creating the dataset, change your mind and change, that the database file should be included in your project, and should be included in the release folder

You can use the same option as you would to include any other existing item in your project.
You can then change the connection string in the Settings for the project, but I'm not sure whether that will work at design time or only run time. You can easily enough just delete the DataSet and regenerate the Data Source.
The data file will be included in the output folder by default, but you should change the Copy to Output Directory property to Copy If Newer unless you want to lose any changes you made during testing each time you build.

Related

single config setting file in a solution c#

I have multiple projects in a solution. Each project has its own app.config file. I want to have a single app.config or settings file which can be used across the solution. What I see is now, when i want to add some settings common to the application I will have to add an entry it in all the projects app.config file.
I want to have a single configurable file (XML) which can be used in whole application. At run time if the value of any key is changed, my application should be able to get that changed value from the XML.
It's a arquiteture problem. Why you can't have a unique webconfig file. Everytime that you need to update an application, will have to update all.
I think It's wrong.
You can to try a solution bellow:
The best and correct option. Uses one commom Redis Cache. Everybody can call it.
Save the configuration in one commom database table. So will have only one update in the solutions changes.
Use a noSql(mongodb, cosmosdb etc.) database. It's faster then sql.
Use one WebAPI. You can consult the configurations and to caching the information in each service.
obs: But if you whant a file. Can put in the solution and create a command to copy and replace the config when to build the solution. Like this:
Copying Visual Studio project file(s) to output directory during build
flw
You can use a linked file for using the same file in multiple projects in the same solution. This is good for using in multiple test projects that run either locally or from a build machine, however, for production code a centralized configuration would be a better approach.
For linking a file via the "Add Existing Item" select the arrow on the "Add" button and then choose "Add As Link".

WPF Desktop app how to include a sqlite DB

I am developing a WPF desktop application that uses a SQLite DB and this is in my App_data folder which is fine while a run it in debug but how do i include a DB file when i build my application and run it on another computer? do i need to build an installer for my app to create a copy of the DB in a location on the users machine that has read/write access?
Thanks
You could create the database in your initialization routines if the database doesn't exist. You can include the location and other settings in your app config. Check this link out: Create SQLLite Database and Table
It sounds like you want to have your SQLite database included in your project output including all the records that were added (i.e. you do NOT want to deploy an empty copy of the database, but rather the same data that you were working with during development).
To accomplish this, add the SQLite database to your project and set the build action to "copy to output location". In your config file, you can then set up the connection string to look for the file in the application directory.
Now, every time you build the project, a fresh copy of the database will be placed in the output directory.

Data lost from .mdf file as I exit application

Recently I work on SQL Server 2008 R2 database. I create database and attach .mdf file of same database in my application with some default data in it . Run application default data coming properly. Now I insert, update some data in my application and its works fine. But as I exit application and again run application lastly added and updated data get lost but default data coming proper as earlier. Please help. Why new
As mention by #Henk , #Microtechie , I scan my project folder and found there are 3 copies of .mdf file are there, 1st in project folder where code project([ProjectFolder ]) resides 2nd in [ProjectFolder]/bin/debug folder and 3rd in [ProjectFolder]/bin/release folder and suddenly solution to my que trigger in my mind. Problem not in multiple .mdf files in project folder, as I every time ‘Clean’ and ‘Build’ my solution new copy of .mdf file from [ProjectFolder] get copied into [ProjectFolder]/bin/debug folder, result in override of last .mdf file in same folder. Hence every time I build and run application only default data coming and last added and updated data get lost.
Thanku all for your replies and precise answer..!
What kind of object do you load your .mdf file data into? It is likely that you need to save the changes in that object before closing the application.

Local database inserts not being stored

This is probably a stupid mistake of me.. but I can't seem to understand it.
I've created a new, empty C# Windows Forms application.
I added a Database (Based on a dataset) and have the file stored in my solution explorer.
I've added a table Test with column Name.
I add a record using new SqlCeCommand("insert into Test values('Name')", new SqlCeConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)).ExecuteNonQuery();
However, I've even tried retrieving the same data and it all works perfectly.
But when I stop my project, and rebuild it.. all data is gone again?
Is there a way to fix this, or will this fix itself when I'll start using this project for what it is intended (Without the 500 rebuilds a day?)
Your database file is listed in the project with this property
Copy to destination directory = Copy Always
If this is true then every time you restart the project a fresh (empty) copy of the database file is copied from the project directory to the output directory (BIN\DEBUG or BIN\RELEASE) overwriting the database file used in the previous run. You could avoid this changing the property to Copy Never or Copy if newer
The answer given by steve keeps copying the database over the existing one, which results in removing all data.
I've managed to fix this by putting "Copy Always" on, then in the explorer move the database to a different location and add it to the project. This way the database will never be overwritten and can be used in the program!
(However, this will probably raise a issue if/when I publish the project to another computer)

Persisting application variables/settings C#

In my application I would like to persist a variable for configuration as part of the the project (I could do it with an accompanying file but that would be evil), so that a change can be made while the application is running and saved such that it can be closed and re-opened and keeping the same value.
What is the recommended or best practice approach to this in a Visual Studio 2010 C# project?
Use App.config or Web.config.
Example: here
Which is the recommended best approach.
You could also save your settings in the Database (if you're using one) and load them at runtime, if you don't want to use "an accompanying file" (although having said that it is still an accompanying file). However you'd have to hard code the connection string to your DB which might be troublesome if the connection string is changed.
Also note that connection strings are usually saved in the .Config file under the tag <connectionStrings></connectionStrings>
Make use of .Config file for saving setting. Developers can use configuration files to change settings without recompiling applications.
Configuration files contain elements, which are logical data structures that set configuration information. Within a configuration file, you use tags to mark the beginning and end of an element.
Configuration Files
and
Configuration Settings File for providing application configuration data

Categories

Resources