I have created a C# application with local database .mdf files.Its all finished.But I am badly stuck where I want to run my .exe file in clients pc.I have searched a lot but totally confused what to do.Mostly everyone has used a SQL server.This is my first project so I don't know the things quite well.I have used visual studio 2015 and I have made a local database in server explorer.
Their .MDF and log.ldf files are made and stored in the path:
(#"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=
C:\Users\SONY\Documents\DATAENTRY.mdf;Integrated Security=True;
Connect Timeout=30");
How can I transfer the .exe file and .mdf files in my clients machine however I have didn't use any SQL server.
Thanks in advance for the help.
you have to install LocalDB through the installation wizard or by using the SqlLocalDB.msi program on the client computer. This may solve this issue
For More Info
Related
How do I go about deploying a database to the ProgramData folder?
I am working with SQL Server Express LocalDB. My steps so far are as follows:
I added a LocalDb database in VS2015 by going to Server Explorer -> Add Connection, and selected to add the .mdf file in the local directory.
I added the .mdf file to the project solution (is this even necessary?)
I set Copy to Output to true.
In Installshield LE, I add SQL Server LocalDB as a prerequisite.
This gives problems when I deploy the application to a different user: the .mdf file doesn't have modify permissions (duh!) so it apparently needs to be deployed to ProgramData (from what I read elsewhere).
I assume this cannot be done at stage 1. above, just by selecting the ProgramData folder when creating the database. So how can it be done?
Thanks!
Update: I am confused about the right workflow when deploying a LocalDb database with an application. I was previously using SQL Server CE, which didn't need server installation, connections and permissions, but needed to move to SQL Server Express LocalDb. This is obviously more complicated, and I have no experience with SQL Server (or database servers for that matter).
I have managed to find a workaround by copying the database to ProgramData and manually setting the folder to give users all permissions, but I feel this is ugly. Is this how people do it? Do people create a local .mdf database file and distribute this in their install projects, or is the database file created programmatically by the application?
It's my first time to Deploy an Application which uses SQL Server Express Database.
I'm Using Entity Framework Model First to contact Database.
and i created a Setup wizard with Install Shield to Install the App.
These are Steps that I'v done to Install The Application in Destination Computer :
Installing MS SQL Server Express (DEST)
Installing The Program using Setup file (DEST)
Detach Database from SQL server and Copy Related .mdf ,.ldf file to the Destination Computer.
Attach database file in destination computer using SQL Server Management Studio.
I know server names and SQL name Instances are different and my program can't run correctly with the Old Connection String.
I'm Beginner at this, and I want to know what should I do in the Destination Computer to make the program run?
should I find a way to change the connection string on runtime?!
or is there any way to modify installshield project and it do this work for me? (installshield is professional edition)
could you suggest me what to do?
in my searches I saw that WiX can do this, but I find it complicated, and i don't have enough time to learn it. i need to deploy the app ASAP.
Thanks alot.
Few hints for using LocalDB in your project:
Download SQL Express LocalDB 2014 here. You can install it silently with single command like this
msiexec /i SqlLocalDB.msi /qn IACCEPTSQLLOCALDBLICENSETERMS=YES
Include your .MDF in your VS project and set in properties to Copy if newer so that it gets copied to your bin folder during build so that it is automatically included in the installer.
At your app startup (in app.cs) check, if database file exists in desired location (e.g. %PUBLIC%\YourApp\Data) (WPF Desktop Application with MDF used locally for all local users). If not, copy the .mdf file from your app install dir to your data dir.
Modify app.config so that your connection string looks like:
<add name="MyContextLocalDB" connectionString="Server=(localdb)\MSSQLLocalDB; Integrated Security=True; AttachDBFilename=|DataDirectory|\MyDatabase.mdf; Connection Timeout = 30" providerName="System.Data.SqlClient" />
Connection timeout should be increased, since LocalDB exe is launched when you first try to connect to it.
You can also use Database.CreateIfNotExists, but I have never tried it.
I have written a desktop application (Windows Forms) in .NET Framework 4.0 using Visual Studio 2010 and SQL Server 2008.
In the /bin folder, it creates an .exe file which works fine on my computer and other computers if they have Visual Studio and SQL Server installed. If they do not have these installed, then it gives report error and the .exe file does not run.
On another PC, I have tested it both on Windows XP sp3, Windows 7 after installing .NET Framework 4.0, and also installed Windows Installer 4.5 for WinXP sp3, but no success.
What is the problem? Is there anything wrong with my connection string which is:
#“Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True;User Instance=True";
How can I make my .exe file run on other PCs?
Thank you, this helped a lot and now I understand the problem is only connection string but problem still not solved. Now I am using this connection string
Data Source=HOME-9BE0D501F6\SQLEXPRESS;AttachDbFilename=|DataDirectory|\shopdb.mdf;Integrated Security= True;User Instance=True
WA-PC was the name of my computer where I was working and it worked fine but when I copied the bin folder to my other pc with name HOME-9BE0D501F6 it still did not worked. I have changed the connection string in app.config file with this name but still got connection error. I have not installed SQL Server 2008 on this pc. Do I have to install it? What else I have to do?
.\SQLEXPRESS means SQL Express instance on local pc, so if no SQL Server installed, then you will get an error.
change the connection string with proper server name
Data Source=<servernameinwhichSQLServerInstalled>\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True;User Instance=True";
If you are using (local) or DOT(.) It means that it has to connect to computer in which application is running. In this case if you dont have sql server or database installed on different computer it will throw this error.
The problem (as already mentioned) is that you are telling the SQL connection to use the local PC name and not the name of the server (where the SQL instance is installed).
A simple way to find this could be to open your SQL Managment Studio / Query Analyser / WinSQL / SQL Script editor and run the following script
use [Database name in question]
Select ##ServerName
Replace your;
Data Source=.\SQLEXPRESS
With
Data Source=##ServerNameResult\SQLEXPRESS
Hope that helps.
How can I deploy a windows form application with sql server database. I've searched a lot, The problem is I want the actual .mdf file when the application got installed on a PC for backup purposes. When I tried the publish feature, it converts the .mdf file into .mdf.deploy. I don't want to attach it into Sql Server Management Studio. I want to publish it with the actual application as .mdf, Kindly guide me in right direction. Thanks
If you nose around on the MS SQL Server site, you find that you can include a 'silent installer' for SQL Server in your .NET project. This will download and install an instance of SQL Server Express as part of your installation process. Just having the .MDF in a folder is useless.
In effect, you have to make at least a few items of functionality that stand in for SSMS: in particular database backups, database compaction, DBCC CHECKDB, etc. You are installing a 'full blown' SQL server instance, with it's separate windows service and system account, so you should be aware of how that impacts your user machine. This gets interesting if it's being deployed to a laptop, particularly a laptop that might sit in a café exposing ports to public LANs.
In general this is a can of worms. It is better to mandate the installation of SQL Server Express first, with SSMS, and merely attach your database to the existing instance. This makes a lot of other operations better behaved.
I'm using Visual Studio 2005. I create a project, not Web Project, just Windows application.
I remember that Access Database File can be added into a project. I don't need connection to server, data can be retrieved. And I want to do the same thing with SQL Database file.
I did the following steps:
Right-click on project.
Choose Add An Existing Item
Browse for *.mdf file.
DataSource Config Wizard appears and it displays this Message
An error occurred while retrieving the information from the database:
Failed to generate a user instance of SQL Server due to a failure int starting the process for the user instance. The connection will be closed.
I need help to add mdf file into my project.
To start with, and MDF file can be read only by an instance of SQL Server. If you deploy MDFs, then your application must either connect to a SQL Server provided by your end-user during setup, or it must deploy its own instance, in the later case a SQL Server Express Edition instance. See How to: Install SQL Server Express. With Visual Studio 2008 you can add a prerequisite to your own application setup MSI, see "Installing" the SQL Server 2008 Express ClickOnce Bootstrapper for Visual Studio 2008 SP1.
A second issue is that, despite the wide belief of the contrary, distributing the MDF alone without the LDF can land you into a world of pain. You can end up distributing an inconsistent MDF that needs the LDF to finish recovery and get into a consistent state.
But a more serious issue is your plan to deploy binaries (MDFs) instead of scripts for database deployment. This is doomed to fail. As soon as you'll plan to release v. 1.1 of your application you'll face the non-trivial problem of how to replace the user MDF (which now contains data added by the user) with your new MDF. This is why is much much better to deploy upgrade scripts always, and forget about the MDF in your project.
You can read from an Access file (*.mdb) in your app without any other requirements because the core Jet engine used by Access is included as part of Windows — it's built in. Sql Server is not included as part of Windows, and so you cannot use an *.mdf file in your app unless Sql Server has been installed and you have appropriate permissions for it.
It is possible to distribute either Sql Server Express Edition or Sql Server Compact Edition (recommended) with your app. Another option is SqlLite, which has a fully-managed database engine available.
An .MDF is a sql server DB, not MS Access. MS access is .MDB. You cannot read an .MDF on its own. It needs a log file (.LDF) as well. If you attach it to your local instance, it will create a new one for you. You can then connect to that DB.
To solve deployement problem (Updated version of your .mdf file and Code), you can have a utility in your application which can create .xls file of every table(Backup your database) which you used in your application. Now you can easly import those .xls file in SQL Server and create new version of .mdf file and attach same file in latest code.Now new release of your app ready to deploye..!