Using database without SQL Server instance (C#) - c#

I'm creating an application with C# using SQL Server. I would like to know if it's possible to run the app on a computer which has no SQL Server. My database extension is .mdf

Using a .mdf file on PC without installing SQL Server or SQL Server Express is not possible. LocalDB version also requires LocalDB deployment.
However, you can use .sdf file but it does not support stored procedures. For this, you need to supply necessary dll files in the app folder.

Related

Project Rider Local Database File

I am looking for a way to include a standart .MDF database to my C# project in Project Rider. I really like the way it works with Databases.
I know that Visual Studio uses Microsoft SQL Server databases, even for local ones, but i can't use a local file of .MDF type for an SQL Server in Porject Rider.
Is there a way to accomplish the connection? If not, what could be a good alternative for a local database?
Thanks!
You can't just use a MDF file directly, it must be used with SQL Server. If you are looking for some kind of local database just to be able to store some data and query it in SQL format, take a look at SQLite or look into Microsoft SQL Server Express or greater.

Understand localDB is relation to SQL Server Express and SQL Server CE

I'm trying to understanding LocalDB by reading MSDN: SQL Server 2016 Express LocalDB and MSDN: SQL Server Express LocalDB and SQL Server Express and a number of SO posts including confusion about SQL Server Express and localdb, I still cannot understand what is LocalDB. I understand and have used SQL Server Express and SQL Server CE.
Questions:
LocalDB...the necessary SQL Server infrastructure is automatically
created and started
My understanding is that, if using LocalDB to handle an application's database, neither the developer nor the client machine where the application is deployed needs to install the heavy SQL Server Express, but just need to install the lighter LocalDB. How, then, without SQL Server Express install can localDB "create(d) and start(ed)" SQL Server? If localDB
... once installed, LocalDB is an instance of SQL Server Express that can create and open SQL Server databases. The system database files for the database are stored in the users' local AppData path which is normally hidden.
If developer or client can use localDB without installing SQL Server, how can localDB be an instance of something that is not installed? Or is localDB an incomplete version of SQL Server Express that just does not need to click..click..click.. to configure. Essentially localDB works like SQL Server CE where localDB use some hidden "files" in AppData to create database while SQL Server CE use the dll to generate the database?
SqlLocalDB.msi program to install the necessary files on the computer
If client still needs to install localDB (which is not really portable along with the application like SQL Server CE), then why not just install SQL Server Express? Either localDB or SQL Server Express is above 100MB+ anyway and need separate installation, what is the point of using localDB anyway?
LocalDB is a programmer-oriented version of SQL Server Express that needs to be installed just like SQL Server Express.
Unlike SQL Server Express, it's not installed as a Windows Service that starts up with your Windows OS - but it only starts up as needed (when your application starts up, or when you start it manually with the SqlLocalDb command line tool).
But LocalDB IS SQL Server Express (not Compact Edition). It uses the same .mdf and .ldf database files like and desktop/server version of SQL Server, not SQL Server CE's .sdf file format.
We used localdb on a project where we had agents in the field using laptops.
The functionality of localdb was better than SQL Server CE (I don't remember exactly what CE was missing, but it was important to the project), you should review the functional differences.
Another advantage was the db was stored in the user folder which makes it impossible for other non-admin users of the laptop to see. This allowed us to reuse and even share laptops between users without mixing data - a nice feature.
Finally, the dbs (with a little effort) can be copied to the dev/support side and restored/attached for troubleshooting. They are full .mdf/.ldf database files.
You do have to create the instances using a command line (sqllocaldb utility), after the product is installed. This was just part of our install app.

How to transfer the local database of wpf application from one computer to other?

I have created a local database in my WPF application,now i want to run the application on some other computer,now how to transfer the local database from one computer to other,and i dont want to create the database manually on other machine? Do we have to convert the database into some .exe file ? If yes,then how to do this or what is the best approach to implement this?
My application accesses its own database file in its own directory with this connection string:
System.Environment.CurrentDirectory + #"\Data\" + databaseFileName;
Please explain from scratch as i am new to this??
I suppose you're running your database in SQL Express. You can use SQL Server Management Studio (included in most SQL Server installers) to export your database, including data, to a .bacpac file.
In SQL Server Management Studio 2012, right click your database, select Tasks, then Export Data-tier Application... and go through the wizard.
Then connect SQL Server Management Studio to the SQL Express server of the target machine. You can do that by connecting Management Studio on your machine to the SQL Express running on the target machine (provided that a network connection exists between the two, and the target machine has been properly configured to accept the connection), or by also installing Management Studio on the target machine, then connecting it to the local server (.\sqlexpress).
Once connected, right click the Databases in the Object Explorer, select Import Data-tier application..., and go through the wizard.

How to add .mdf file to create .exe setup file in C# windows application

I created a C# windows application with sql server, 2008 database as backend. I would like to deploy the project along with .mdf file so as enable on client computer to create a database folder when the project is installed on it.
Client computers wouldn't have SQL Server installed (that's what's on the server). It doesn't make sense to deploy the MDF file.
Besides, Deployment/Setup projects do not come with a step that attaches a database file to a server. I wouldn't recommend distributing a database in binary form anyway - if it's a new application I would run a setup SQL script from within my application, this means that your application will work against a variety of SQL Server versions (as MDF files are not necessarily transferrable between SQL Server versions without some massaging).

Connecting a client-Installed C# application to an exported SQL Server database

I'm very new to creating installers. This application needs to connect to a SQL Server database for it to be used. The tables of that database has rows which are needed by the application, so just reconstructing the database structure is not what is needed.
Can I just export the database as a .mdf file and connect from there?
Or do I need to install SQL Server Express on those computer as a prerequisite and attach the database from there? If so, how do I attach it on installation?
Or are there other ways to include a SQL Server database to an installer and be used by the installed app?
On the target machines you need to install SqlServer (express or standard).
You don't need any management application like Sql Server Management Studio.
Then you can attach your MDF to the database engine via connection string as this one
Server=.\SQLExpress;AttachDbFilename=c:\yourfolder\yourfile.mdf;Database=yourdatabase; Trusted_Connection=Yes;
The installation of SqlServer is not an easy task to do via custom installers.
If your application is not intended to be used outside of the local machine you could use LocalDB.
The install of this flavor of sqlserver is more easy.
Other alternative is:
Extract a sql script that rebuilds your database. (and provide a method to execute the script)
Export the data needed and execute a bulk insert to reinsert the data in the rebuilded database

Categories