0

I am working on a small windows forms program that reads data from a local database, which I have created by following this guide.

I have populated these tables with data using the Designer in Visual Studio, and there is no ability (nor will there ever be) for the program to make changes to this database at run-time, as they represent static, known data -- I could get identical results if I hard-coded the instantiation of each corresponding table row object in a constructor somewhere.

When I have Visual Studio build my solution, it generates two files -- the .exe that opens the Form, and a .mdf file with the database tables.

Two related questions -- does it even make sense to use a database with this kind of read-only data? And if so, is there a way to combine the .MDF file into the .exe? Again, there is zero need to ever modify the data, so I wouldn't think that the fact that you can't modify .exes need prevent this.

4
  • 1
    Depends how you use the database; If you are using it as a flat information store only and simply loading all the data into memory once then as you suspect a database is a poor choice. An alternative would be to embed some XML as a resource: stackoverflow.com/questions/2820384/… Commented Mar 28, 2017 at 14:41
  • The database file can only be processed by a database engine, so no, there's no stuffing that into your executable. You could take a look at lighter-weight options like SQLite if your data is substantial enough that storing it as tables still makes sense (as opposed to, say, XML resources). Commented Mar 28, 2017 at 14:42
  • @AlexK. It's not flat, but XML (or JSON, I guess?) resources files probably make as-much or more sense. That's a useful link, thank you. Commented Mar 28, 2017 at 14:56
  • You can make an two accounts in SQL Server. One with Full Access and another with Read Only Access. Commented Mar 28, 2017 at 15:20

1 Answer 1

1

Yes you can do this. But first you need to construct your dataset. I would create your data in SQL or similar then export it to XML along with an XSD schema.

Then in Visual Studio, add a DataSet object to your project.

Then you can talk to the DataSet object and use the XSD and XML to populate it.

https://msdn.microsoft.com/en-us/library/atchhx4f(v=vs.110).aspx

To keep this all within the .EXE, embed your XML data into a Resource file, then access it via the Resources static class.

Sign up to request clarification or add additional context in comments.

3 Comments

Exporting from the database to XML is brilliant. I think that's exactly what I need! Is there a way to do that from within Visual Studio?
I'm not sure. I've always used SQL commandline "sqlcmd -S <your-server> -i input.sql -o output.xml"
You need to add :XML ON attribute to your SQL.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.