0

In my application I need to use a local database (the application I'm creating works with everything locally). I had one database that worked really bad, because sometimes it saved the data and other times don't. And if I published the program I couldn't find the database file.

But I am having some trouble to know where to place the database. I have created one in E:\PAP\Trabalhos\Trabalhos\database.mdf and other in E:\PAP\Trabalhos\Trabalhos\bin\Debug\database.mdf, but in any of those paths the database is recreated/goes back to the previous state, when I try to start the program.

In my connection string I have this:

Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|database.mdf; Integrated Security=True

and that points to the file ...\bin\debug\database.mdf

I want to be able to access the database in any computer I use the program and be able to actually save data.

Where is the recommended path to place the database file and be able to access it independent of the computer I am using?

Should I use Windows authentication or SQL Server authentication?


tl/dr: Database doesn't save data and I want to be able to access it in any computer without any extra steps.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Do you have your database file listed between the project files and its property Copy to Output Directory is set to Copy Always? – Steve Jun 02 '19 at 09:42
  • Yes, the database.mdf is in project files and copy to output directory is copy always, but something I noticed now its different is the icon. now is just a blank "paper" with a warning icon in the bottom right corner, instead of the database icons. And I don't see the log file of the database. – Gabriel Valente Jun 02 '19 at 09:53
  • See the answer https://stackoverflow.com/questions/23496393/data-not-saving-permanently-to-sql-table – Jonathan Willcock Jun 02 '19 at 10:16
  • 2
    You shouldn't need to know where to *place the file* - SQL Server is - as the name already tells you - a **server-based** system - you just connect to it and use its services - let the SQL Server handle all its nitty-gritty details of where to put and place the files - don't fiddle around with "free-floating" `.mdf` files - this is just a mess and nothing but grief. Put the database **on the server** (where it belongs) and just connect to it from each of the clients. – marc_s Jun 02 '19 at 10:25
  • So, I just did that now, I created a database and just gave it a name, and what is the connection string? – Gabriel Valente Jun 02 '19 at 10:45

1 Answers1

0

You can't use "(LocalDB)\" and access it from any computer. LocalDB is by design accessible only from the applications running on the same computer (it is an embedded database).
To access database over the network you need to install instance of SQL Server, like full SQL Server Express instance or use some cloud service like AWS or Azure.

Piotr Palka
  • 3,086
  • 1
  • 9
  • 17
  • I know, what I mean is if other person use my application in their computer. I want them to be able to access THEIR database, without changing any path to the database file. – Gabriel Valente Jun 03 '19 at 10:44