Author Topic: Local Database / Service based Database in Community 2019  (Read 2648 times)

halosome

  • Newbie
  • *
  • Posts: 31
    • View Profile
Local Database / Service based Database in Community 2019
« on: September 10, 2019, 05:25:17 PM »
I am trying to store some settings of the screen I created. I can store to a csv file there is no problem, but I am thinking to store to a database, so my question is does the Visual Studio Community 2019 have a database installed itself?

I did some search and seems I should have a Local database, no extra software needed. However I cannot find Local database from the Add New Item list, only Service-based Database. Could I use the service based database without install extra software? The PanelPC is from this website.

If I could use it without extra software, can anyone share a sample code?

Thanks!

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Local Database / Service based Database in Community 2019
« Reply #1 on: September 10, 2019, 05:26:47 PM »
Not 100% sure, but I believe even the local database needs SQL Server Express installed.

halosome

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Local Database / Service based Database in Community 2019
« Reply #2 on: September 10, 2019, 07:25:57 PM »
Thanks Archie. Though I don't like install extra software but sql server express localdb 2017 is only 47M. I have downloaded and installed and I will test it tomorrow.

Phrog30

  • Guest
Re: Local Database / Service based Database in Community 2019
« Reply #3 on: September 10, 2019, 10:52:03 PM »
If you don't want to install anything but want to use a database I recommend sqlite.

Noe

  • Full Member
  • ***
  • Posts: 205
    • View Profile
Re: Local Database / Service based Database in Community 2019
« Reply #4 on: September 11, 2019, 08:43:03 AM »
If you only want to store settings, there is a couple of simple options that does not require installing any software.

You could use my.settings variables, to store locally your settings. The downside is that if you move the application they are not going to move with it, as they are saved in the user profile folder, I do not know exactly where.

Another option is to use a datatable for settings, and store it in an xml file. Saving it and loading it is very easy, just google and you'll find plenty of examples. And this will be kept in the same folder of your application, unless you specify otherwise.

If you really want to store a lot of data with the database functionality but not having to install anything at your PC end, SQLite is good option, or also an Access database could be used using ADO.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Local Database / Service based Database in Community 2019
« Reply #5 on: September 11, 2019, 11:41:45 AM »
Phrog30 has uploaded projects with SQLite, so if you decide to go that way then check this topic for the code:

https://www.advancedhmi.com/forum/index.php?topic=1813.0

Make sure to read everything and check other topics since he'd been updating stuff.
« Last Edit: September 11, 2019, 12:25:40 PM by Godra »

halosome

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Local Database / Service based Database in Community 2019
« Reply #6 on: September 11, 2019, 12:50:58 PM »
Thanks everybody,

After I saw your recommendations I downloaded the sqlite 3.29, the precompiled Binaries, sqlite3.dll, both 32 and 64 bits. But when I add reference it says Could not be added, please check the file is accessible, and it is valid assembly or COM component.

Then I open the nuget, only sqlite 3.13 is available.

Are you using the 3.13 or do you have a way to install the newest one?

halosome

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Local Database / Service based Database in Community 2019
« Reply #7 on: September 12, 2019, 12:51:21 PM »
I downloaded Phrog30's project and found the sqlite3 I downloaded is for windows, and there is another link for .net frameworks.

However I started using MSSqlLocalDB. And now I have spent several hours and could not solve the problem

I setup a database (master.mdf) with a table (myTable) from Server Explorer, and I insert a few lines of myTable, from VB2019 (dbo.myTable[Design]) with Query from Server Explorer. It seems that database is fine.

But when I do it from VB, any sql query, it pops up an error: System.Data.SqlClient.SqlException: 'Invalid object name 'myTable'.'

Thanks for any help.

halosome

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Local Database / Service based Database in Community 2019
« Reply #8 on: September 12, 2019, 02:41:21 PM »
I just found the problem, when i setup the LocalDB I chose to create MDF in the output folder, however VS still shows the original but actually there are two MDF, I pointed to  to the original which is not the correct one.