Automatically install access database when creating setup file in c# - c#

I Have created a c# application which is using access database.
I have deploy the application successfully.
what I want is install the access database automatically in other users computer automatically.
I have tried to change the app.config files connection string and no use..:(
help me

Not sure what you mean, but if your database is part of your solution you can copy it to the output directory:

You have to be more specific. Did you install the application using installer? Copying and pasting?
Maybe these would help:
StackOverflow - "How to install visual studio 2010 setup project with MS Access database on a computer which is not having Office 2010 installed?"
CodeProject - Deploy your Application and Database
MSDN Forums - "How to attach sql database file to creating .exe setup in c#"

Copy the access db to a folder in programdata with the setup. Connect to this db in your code. You don't need a connectionstring in app.config if the user is not allowed to specify the db path.
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
Your setup should be able to deploy to a programdata folder.

If you want to create .exe Setup Project of your Dot Net Application which is using MS Access DATA BASES. then simply follow this steps. Please read this one for a moment before to proceed these steps.Connect with MS Access Data Base in Dot net.
When you are going to create the exe file then your data base connection string should be like this(means there should be no directory in #"Data source, Just direct put the name of your data base, because in .exe file when you add your data base file, then it is in the same directory.
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;" +
#"Data source=MyDataBase.accdb";
Right click on your solution file. (like in Solution Explorer "Solution 'MyProject' ")
Select Add -->New Project -->Other Project Types
Select "Setup"
A New project will be added named setup (with a new tab added to
editor as File System )
Now right click on application folder -->select add -->select folder
new folder will be added under application folder * Now Right click
on newly added folder -->select add -->select file * Add File dialog
will be popup
Select your Db file (means from a "Browse" Button there go and select your Access Data Base )
Select Setup project and build.. Now your
installer will have your DB.
You can also install it from there.

Related

Deploy SQL scripts stored in a folder along with click once installer

I am working on a windows forms application in which I am using few SQL scripts and executing them in my server using the C# application. Everything is working fine. I am able to run the scripts in my application which in turn creates tables in the database specified.
However my issue is I want to ship these SQL scripts located in that folder along the clickonce installer while deploying. The installer does not include the SQL files while installing.
Below is my code.
lstInfo.Items.Add(Resources.domaintable_initialization);
var file = new FileInfo(Path.GetFullPath(Application.StartupPath + "/scripts/createtbl_script.sql"));
SScriptFile = file.OpenText().ReadToEnd();
SUpdateDBname = SScriptFile.Replace("db_project", database);
var sUpdateServer = new Server(new ServerConnection(sqlConnection));
sUpdateServer.ConnectionContext.ExecuteNonQuery(SUpdateDBname);
sqlConnection.Close();
lstInfo.Items.Add(Resources.domaintable_success);
I have added the scripts folder inside debug -> bin directory. However when I publish the package i am not able to call the scripts located in that path as that folder inside bin is not getting published and I am getting the error that the path is not valid and scripts not getting called once installed using the clickonce package.
Can anyone help me on how to achieve this? I want a path to which I will be able to add the SQL scripts and able to have the same scripts added to my deployment package once published.
You need to include these files in the visual studio project. Just right click on the project and add an already existing element.
Select your scripts and add them to the project.
After that right click on the script files an click on properties. Now you will see a property build or something like that. There you can use the dropbox and select 'Content'.
Below that you will find another dropbox which should read something like "Dont't copy". Set the value of that dropbox to "Always copy".
That should do the trick.

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.

publish a project with local database

I created a Windows form applicatie with a local database (.mdf) to store and retrieve data from.
the database where I connect to is:
C:\ProgramData\project\Database.mdf
when I publish my project and place my database file in that folder on a other pc and try to run it I get the error unable to locate a local database runtime installation
my connection string is:
conn.ConnectionString = #"Data Source=(LocalDB)\v11.0;AttachDbFilename=""C:\ProgramData\project\Database.mdf"";Integrated Security=True";
so could somebody help me with this problem?
because everything runs fine on my own pc
Did you include the database as "Application File"? If not do the following (at least this is how I am doing it):
Project -> Properties -> Publish -> Application Files
Here set the values for your .mdf and the xx_log.ldf as follows:
Now still in the Publish tab go on Prerequisites. Here you have to check the following depending on what database you are using.
This will download SQL Server Express for the client who is installing your application.
You will also have to change the connection string to a generic path. I suppose the database lies somewhere inside your project folder /bin I guess, not sure anymore. So adjust your connection string to something like:
Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True
I therfor recommend using a resource file or app.config
But basically i think your problem is that the pc you are installing on does not have SQL Server installed. So just follow the steps above in Prerequisites. The other steps will enable you to deploy the database to the project folder without moving it to a certain folder manually.
I hope this helps.

Unable to update database .MDF is Read Only

I have a local DB that I have in an application. When I install it on another machine I get the error
Unable to update database.. .mdf is read only.
I was able to get around it by editing my permissions on the .mdf and log file themselves. I did some research and noticed that I may want to install the database to a shared folder. However, I am not sure how to do that and the answers I did come across did not make a whole lot of sense to be.
//My connection string
SqlConnection con = new SqlConnection(#"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|AssetDatabase.mdf;Integrated Security=True");
Any guidance would be greatly appreciated. I am learning.
Just go to the program files and find the folder of the installed program.
Just right click the .mdf file in the folder and click PROPERTIES.
In PROPERTIES TAB -> SECURITY -> you'll see Group or Usernames.
In that select the User to which u want to give Access to the file.
If for that user the PERMISSION is not set to FULL CONTROL.
TO CHANGE PERMISSIONS -> CLICK EDIT.
Now the Group or Username box will open.
In that Select The User -> Select FULL CONTROL in Permission Box.
Now follow the steps for the log file too. IF Needed.
OR
Just install your application in different folder other than ProgramFile(x86)
The MDF file would be readonly either because the readonly file attribute flag is set, in which case you have to unset it, or another program has the MDF file locked as readonly. Are you running a version of SQL server that is using that file?
I've never seen a connection to the MDF file directly, usually it's done via the server, and the server will manage all the IO for the MDF file.
E.g. a typical connection string for SQL Server:
Database=<dbname>;Server=<servername>;MultipleActiveResultSets=True;Connection Timeout=10;User Id=<username>;Password=<password>;
Additional links:
1) Failed to update .mdf database because the database is read-only (Windows application)
2) Failed to update database because it is read-only
3) Failed to update database "*.mdf" because read only EntityFramework
4) http://www.codeproject.com/Questions/183758/Failed-to-update-mdf-database-because-the-database
First stop the SQLEXPRESS service from local-Services menu and then try to move and connect the database again by attaching database option in SQLEXPRESS. it should work. it works for me. :)
I solved the same problem as follows:
While creating "Setup", I manually added my database files database.mdf and database_log.ldf into the Application Folder file. But after adding these files, make sure that the ReadOnly option in the Properties section is False.
Also "connectionString" I use:
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\database.mdf;Integrated Security=True;Connect Timeout=30"
just remove the .mdf file location to c:\ or desktop or anywhere but not in
%program file directory
if your database file on the C volume,
try to move the .mfd file to D volume

how to link to access database file in created .exe file with c#

I want to create setup file for my C# project. I use access 2010 with my project. I link to database file in every form of my project. This my database link
OleDbConnection db_con = new OleDbConnection(#"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\HUNAR\Desktop\Bashi Nawxoyy\Bashi Nawxoyy\bin\Debug\db_file.accdb;Jet
OLEDB:Database Password=RTm$&9sdfZXC;Persist Security Info=True");
know in creation of setup file I want to config access database file in app.config file and call it in every form. Also I want to attach db file with the setup file and the setup file be able to connect to db file in every machine that i install the setup file on it?
If you want to create .exe Setup Project of your Dot Net Application which is using MS Access DATA BASES. then simply follow this steps. Please read this one for a moment before to proceed these steps.Connect with MS Access Data Base in Dot net.
When you are going to create the exe file then your data base connection string should be like this(means there should be no directory in #"Data source, Just direct put the name of your data base, because in .exe file when you add your data base file, then it is in the same directory.
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;" +
#"Data source=MyDataBase.accdb";
Right click on your solution file. (like in Solution Explorer "Solution 'MyProject' ")
Select Add -->New Project -->Other Project Types
Select "Setup"
A New project will be added named setup (with a new tab added to
editor as File System )
Now right click on application folder -->select add -->select folder
new folder will be added under application folder * Now Right click
on newly added folder -->select add -->select file * Add File dialog
will be popup
Select your Db file (means from a "Browse" Button there go and select your Access Data Base )
Select Setup project and build.. Now your
installer will have your DB.
Some screen shot which will help you

Categories

Resources