VB.net connection to embedded database - vb.net

I have a stand-alone Windows Form app written in VB.NET that currently connects to a local Access DB (.mdb file) and consumes data from several of the tables. It never writes to nor modifies the DB. I'm trying to figure out how to secure this DB so the user has no access to it. I'm thinking the best way is to store the DB as an embedded resource within the project. However, I can't figure out how to make this work.
I've added the .mdb file to the project resources and set its properties to "Embedded Resource" and "Do not copy." But now how do I reference the DB to create the connection?
Before I used the connection string "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=MyDatabase.mdb"
How do I write the connection string now with reference to an embedded resource?

"I'm thinking the best way is to store the DB as an embedded resource within the project."
This usually relates to old skool security, in the olden days DotNetNuke developers that used Access dBs as their backend actually renamed the .mdb to .resources as you cant download a resource file from the web.
"Would it be better to export the DB to xml or something like that and then use a stream reader as opposed to a database connection?"
No. You cant read an Access file from a stream And an XML dB has even less concurrency support than an Access Database.
If you really need to protect the data, then you've absolutely chosen the wrong data store.
#JohnBustos wrote "Store the DB remotely and have the program access it over the internet."
Please do not do this. If anything put it on a network share and restrict access. Then look at upgrading the access dB to SQL Server.

Yes, I have had the same problem and I converted the database into a XML or even a TXT file that is embedded. It works very fine !

Sorry, I never closed this out.
My solution was even simpler than those proposed. You can add the .mdb file to the project itself and not mess with the whole "Resource" business. Then set the file's Copy to Output property to "Do not copy". So the .mdb gets compiled into the app, but file itself is not available to the user.

Related

Users to fetch files remotely

I am using ADO to connect to an access database from an excel spreadsheet using code written in vb. The spreadsheet allows someone to retrieve files stored locally on my machine according to what they enter in certain cells and from interrogating the database. This has worked well which presents the frightening prospect of me now feeling encouraged!...
It is my wish to give a copy of my spreadsheet to people but retain the files and database on my own computer or a dedicated server. ( I do not want the users to be able to access anything other than a view onto the data or the files that I allow them to access). I totally appreciate their are a myriad of alternative technologies that I could and might need to achieve this. But I really am quite a simpleton and would like to be able to simply amend my connection string with something that uses an IP address and similarly with the files. Is this even possible? Can someone advise me where to even start looking for a solution if it is not? I've browsed through stuff on VPN's, application servers, ASP's etc. without even knowing if it is relevant and, as I say, I need the dumbsters solution. I'm happy to read - but what......should I look at VB.net?
A VPN would allow a similar setup to what you have now in as much as your would need to modify the connection string and file paths (to network share paths) but has drawbacks:
Users/you would need to configure a VPN client
Your machine would be the host so would need to be always-on with sufficient bandwidth
Users would be logging on to your machine so you would need to manage access rights/security
This is difficult to scale and a pain in to manage, which is something that is also true of attempting to serve Access content over the internet.
A more standard way to do this would be to:
Get an ASP.NET hosting account with SQL Server support (or set this up on your machine)
Migrate the Access data to SQL Server (which unlike Access is specifically designed to support multiple users over a network)
Update your VBA connection string and make any required changes to your SQL
Create an ASP page that reads the files stored on the server and returns their content
Modify the code you have that loads files from disk to instead query this ASP page over HTTP and read its contents
Retaining Access; you could also create a ASP page that executes queries, reads the data and converts it to XML returned to your spreadsheet for processing.

How do I assign a URL to a file stored in a SQL database?

I have a self-made document management system that stores files of all sorts in an SQL database. The database stores 4 basic rows of information, namely:
FileID
FileName
FileSize
FileType
FileContent
I want to use viewer.JS to preview files, but it requires that I have a URL to access my file, and I have no idea how to assign a URL that would access a file of my choice in a row in a database. I'm building on a home-grown PAAS, thats built on .net.
I've heard that the URL rewrite module for IIS (I'm on 7) may solve my problem, but cant seem to crack it.
Any help on my problem would be much appreciated.
IMHO IIS rewrite would not help you. Assuming you're using .net, you'd need to build a simple website and use routing in a view.
The url could be something like /Document/{fileid}. when this path is encountered, the router would call your view and you can return the file's content.
Store file in SQL Server database using .Net MVC3 with Entity Framework has some info on a model/controller.
Note: There are some security issues with this approach.

Access a accdb file (MS Access 2007) from resources

probably this is a simple question but because i have never used resources like that i can not think how should i do it.
I am writing a very simple program that connects to a accdb file (Microsoft Access 2007 file) and returns some results in a datagridview. Everything is fine. Now because we have to deploy this program in many computers i publish it so everyone we want can install it and have updates. What i wanted to do is to make the database file part of the program which i did it by adding it to the resources. My problem is that i do not know what connection string to enter in order to access it in my resources.
My previous connectionstring before i deploy it was this
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\bl.accdb;Persist Security Info=True
What should i change in the data source in order to access the same file in my resources? Or am i wrong and this is not possible?
Thanks
You can do it. All you need to do is point the datasource to the location of the resources direcory, which by default is adjacent to the application itself. You could determine this at runtime by using:
Application.StartupPath & "\Resources\DatabaseName.accdb"

How to edit a Word Document (.docx) stored in a SQL Server Table?

How to edit a Word Document (.docx) stored in a SQL Server Table?
Here is the tentative work flow:
Read BLOB from SQL Table through Ideablade
Write BLOB to disk as .docx
Open .docx using Word
User makes changes
Save .docx using Word
Read .docx into BLOB
Write BLOB back to SQL Table through Ideablade
All sample code is welcomed?
I am sure there are a lot of people doing this already.
Any other ideas on how to simplify this process?
I am using VB.NET, .NET 3.5 SP1, WinForm and SQL Server 2008.
Well, as to the how, here is how to read a blob and write a blob to SQL. Although frankly, unless you have very good reasons such as an existing backup system, you would probably be best served storing the file to the file system and the path and metadata in the database. Either way, abstract it in your BLL, so you can change your mind down the road.
Retrieving and updating the BLOB from the db shouldn't be a problem, you'll find lots of sample code to do that on the net.
A simple approach to your problem would be to create a "temp" or "working" directory somewhere and monitor it with System.IO.FileSystemWatcher (sample code). When the user wants to edit a file, fetch it from the db and store it the directory. Whenever the user saves the file, you'll get a notification from your FileSystemWatcher, so you can save it to the database. Don't forget to empty the directory from time to time.
The method I've seen for this that I think works best is to build this as an add-on for MS Word itself. Examples include the Save to Sharepoint, Save to Moodle, and other similar add-ins.

Creating Simple desktop database application

I am here to write a small database application that will be running in desktop (offline mode).
I am using MSAccess 2007 as my database file and trying to write code in vb.net.
I used to write the code vb6 an usually had global variables for storing database connection and executing every query from that.
I am trying to upgrade myself from vb6 to vb.net.
do i need to read some more simple starter books also?
In .NET, talking to a database is handled with ADO.NET, which uses something called "connection pooling". The connection pool is basically a collection of open connections to your database that ADO.NET manages for you. In your code, when you create and open a Connection object, ADO.NET first looks in the connection pool to see if it already has an open connection to your data source, and if it finds one it uses that (instead of actually creating and opening a new connection). When you close your connection, ADO.NET does not really close it, but instead returns it to the connection pool.
Therefore, you do not need (and in face do not want) to maintain open connection objects inside your application (in a global variable or anywhere). The correct approach with data access in ADO.NET is to create and Open a Connection object, do whatever you need to do with the database, and then Close and Dispose your Connection.
Store the connection string in the config file (in the solution explorer, open the My Project folder and doubleclick on Settings.settings).
I'd suggest that you create one or more classes to contain your database code and let those classes convert between the database data and your application objects, most VB6 projects I saw had the GUI hard linked to the DB which can make future maintenance or new features very difficult and limits the possiblity of code reuse.
If you've got VB6 experience I'd thought that you could probably start trying to create the application right away but you should definitely read either a good book or good articles about it at the same time so that you pick up things like that you need to Dispose of your database objects after user etc.
It's probably a good idea to get a book, a lot has changed since VB6.
Also consider using a more robust db, like SQL compact or SQLite. It will allow you you use the Entity Framework which will make writing your app a whole lot easier.