Question

cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=C:\solutionvs10\test\test\bin\Debug\db2.mdb;**Jet OLEDB:Database Password=secret**")

cn.Open()
''# codes
cn.Close()

I used V S 2010 The above is my code......u can see that it is Ms Access DataBase....(password protection) How i can create a setup .....that can be easy to install other computer.........

Can i Create such a setup ???

Was it helpful?

Solution

As Will pointed out including the .mdb file into your project is probably what you are looking for. You can do it in the project manager and then adjusting the properties so that the file is published to the application folder (Copy to Output Directory = Copy Always).

In the code, you should then refer to the database as

cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & My.Application.Info.DirectoryPath & "\db2.mdb;**Jet OLEDB:Database Password=secret**")

since you don't know the installation path of your database on the client's computer.

On the other side you might want to make sure that you publish your application as a 32bits application since the Jet4.0 does not work for 64bits applications (see http://connect.microsoft.com/VisualStudio/feedback/details/123311/win-xp-x64-jet-v4-0)

OTHER TIPS

First of all, this code you posted is wrong:

cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=C:\solutionvs10\test\test\bin\Debug\db2.mdb;**Jet OLEDB:Database Password=secret**")

cn.Open()
''# codes
cn.Close()

The reason it's wrong is because you're not guaranteed to close your database connections, eventually leading to a state where your database is not accessible to your application. This won't happen in your development testing, because such tests tend to be short-lived, but it will happen to your users, who tend the keep applications running over longer periods of time.

Now, I know you're thinking, "Yes, I am closing my connections. Don't you see the cn.Close()?" Yes, I see it. But that's not good enough. There are a few cases (exceptions are the big one) that can cause this code not to run. The correct way to write this code is like this:

cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=C:\solutionvs10\test\test\bin\Debug\db2.mdb;**Jet OLEDB:Database Password=secret**")
Try
    cn.Open()
    ''# codes
Finally
    cn.Close()
End Try

And there's a short-hand syntax in VB.Net that looks like this:

Using cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=C:\solutionvs10\test\test\bin\Debug\db2.mdb;**Jet OLEDB:Database Password=secret**")  
    cn.Open()
    ''# codes
End Using ''# No need to call .Close() any more, the Using structure takes care of it

Now, on to the actual deployment question.

You need to add a setup project to the same solution that holds your application project. You should then be able to use the output of your main project as the package for the setup project and include your initial database file as a content resource. There is no need for anything else included in the setup project; Windows includes the Jet database engine used by access out of the box. You may want to spend some time making sure that the appropriate .Net framework runtime will be installed as a dependency if needed as well.

For easy install on another computer, I recommend SQLite or SQL Server Compact. Configuration may also be more difficult with access than sqlite or mssql compact.

Beyond that, I would recommend deploying the application using ClickOnce. Documentation here.

I think that making the MDB file part of your project, and setting the right property for it to be copied into the application folder will do the trick.

On the other hand, you will have to make sure you set the MDAC 2.8 as one of your project dependencies so that your users are either informed or required to download and install it to their computers.

I do think you may deploy through ClickOnce, otherwise create a SetUp project, that is doable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top