Using Visual Studio 2017, for a C# project, how do I create my SQL database in a separated and portable file?
-
1you create a database project..... – Mitch Wheat Sep 22 '21 at 09:56
-
inside my solution? (I'm not exactly a pro and I'm just building a tool for a social study) – Mario LOBO Sep 22 '21 at 10:05
-
1Do you mean to create a project built-in database? – Jiale Xue - MSFT Sep 22 '21 at 10:09
-
@JialeXue-MSFT, I want something I can grab and send to another computer. I can do that with an ACCESS file, but my data will exceed the 2GB largely. The scenario is: I have a software that I will run to gather data. This software will, hopefully in a near future, allow to consult the data. But if I am the "gatherer" the "reader" will be someone else. I need to send the data there. – Mario LOBO Sep 22 '21 at 10:12
-
1Sounds like you want localdb https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb?view=sql-server-ver15 – Nick.Mc Sep 22 '21 at 10:59
-
Any specific dbms in mind? (There are dozens of different SQL databases.) – jarlh Sep 22 '21 at 11:45
-
@jarlh, I'm way off my league developing this software. So... the one more intimately connected to Microsoft and Visual Studio. – Mario LOBO Sep 22 '21 at 12:18
-
@Nick.McDermaid, I'm using localdb. But my question is how can I transfer the data to another computer. Without sending other databases I may be using. Does localdb create a separate file (set of files) for each database? – Mario LOBO Sep 22 '21 at 12:18
-
1Yes it creates two files per db https://stackoverflow.com/questions/18371902/how-can-i-move-a-sql-server-localdb-database-from-one-machine-to-another – Nick.Mc Sep 22 '21 at 22:30
-
@Nick.McDermaid, thanks. If you want the "correct answer" tick please reply (instead of comment) and I'll vote you up. – Mario LOBO Sep 23 '21 at 14:05
2 Answers
The Visual Studio "native" database is LocalDB. This information goes out of date quickly but here is the current situation, summarised from the link below
- LocalDB can be installed through the Visual Studio installer
- The
SqlLocalDB.exe
utility lets you manage LocalDB (i.e. start/stop/create/delete) - LocalDB cannot be managed remotely via SQL Management Studio.
- One "automatic" instance of LocalDB exists for every version of LocalDB installed on the user's computer. This is public and is created and managed automatically for the user
- The easiest way to use LocalDB is to connect to the automatic instance owned by the current user by using the connection string
Server=(localdb)\MSSQLLocalDB;Integrated Security=true
. To connect to a specific database by using the file name, connect using a connection string similar toServer=(LocalDB)\MSSQLLocalDB;Integrated Security=true;AttachDbFileName=D:\Data\MyDB1.mdf
I've never managed to find clear instructions on how this should be deployed. Suffice to say you should be able to easily install LocalDB on the target machine and deploy your MDF file for it to use.
If you would care to expand on your use case, there might be other options.
I have a software that I will run to gather data. This software will, hopefully in a near future, allow to consult the data. But if I am the "gatherer" the "reader" will be someone else. I need to send the data there.
For example you could use a cloud database (Azure SQL would be the visual studio native platform). You don't need to install anything, it's automatically backed up. It's publicly accessible to anyone (and can be locked down). Downside is it's about $8.00 USD a month for 250Gb

- 18,304
- 6
- 61
- 91
An SQLite database is a single file. The tables and data, triggers, foreign keys, and constraints are all stored in this file. Your application reads and writes to the database by calling SQLite. When you do a SELECT or UPDATE, SQLite reads and writes to the file....
Copied this text from here: https://www.c-sharpcorner.com/UploadFile/afenster/using-sqlite-with-net/
You can also see an example of how to use the DB at that page. There are many other tutorials on the web.

- 794
- 5
- 13