How to install a custom desktop application database to SQL Express? - sql-server

I have a WPF desktop application that uses a custom database for storage.
I need to prepare a setup project (from Visual studio 2008) (full setup, not ClickOnce).
I can add the to the list of prerequisites to the application and it does install during the setup of the application.
My question is: How can I run a script during the setup to create the database that the application needs? OR how can I restore the database to the client machine during the setup?
Another related question, what would happen if already exists on the client machine? How to detect the instance name and connection data? And then how to be able -if needed- to change the Connection string used by Entity framework to connect to that database?
Thanks,
Ed

SQL Server Express Edition is generally a really poor choice for a local database. It's a server-class engine that likes to use a lot of resources and runs as a service (so it's using up those resources even when your app isn't running). In other words, it belongs on a server.
The only place I've seen SQL Server Express used on a desktop that almost makes sense is as part of the Microsoft Small Business Accounting app, and in this case you generally install that program on a machine who's primary purpose is doing the accounting for your business.
What you should do is use a desktop or in-process class engine like SQL Server Compact Edition, Sqlite, or even Access. This will also greatly simplify your deployment.
If you insist on pushing through with this, know that the installer will create a new instance of sql server on the system. SQL Server will be fine with this. However, you'll need to account for that in the connection string of your app, and that can be a little more complicated. Additionally, to set up the database you have a couple options:
Create it from client code on first start of the app
Create it with a custom installer action (hard to get right because msi permissions)
Distribute an pre-build *.mdf file and attach with custom installer action or on first start of the app.

Related

Using Microsoft SQL Server with Windows Forms application (vb.net)

Ever since I started vb.Net programming, I have been using MS Access as back-end for all my programs.
It is easy to publish application with the MS Access database and run it on another PC without installing the MS Access database.
But now, the project I am working on needs a database with high storage capacity which means MS Access is no longer an option and I have chosen to use SQL Server. Now my question is do I have to install SQL Server on any system that the application will be run on? If so, how will I copy the database that I created on my development machine to other system so that my application will connect to it? Or is there any simpler way of doing this?
SQL Server is a client/server DBMS so you only install the database on the shared server. .NET includes SqlClient, which provides the client components needed for SQL Server applications.
There are a number of options for database deployment. Although you could use restore or attach your development database for the initial database deployment, that won't work well for future upgrades (assuming you want to keep data). Consider using T-SQL scripts and/or SQL Server Data Tools (SSDT). That will allow you to create new databases, such as for development and testing, as well as upgrade existing ones.

How Can I Use A SQL Database Like I Used To Use Access?

I have been supporting a product written in VB6 with an Access database for a long time. In many of the installations a mapped drive was used to allow multiple workstations to run simultaneously. Since it seems Microsoft has broken that recently, I need to re-write everything with a new set of tools.
I plan to use VB.net and I would like to use a SQL database this time for the stability. The problem is that the market I sell to cannot / will not support installing full blown SQL Server and all the complexities of managing it.
What I am not able to find any current info about is whether or not SQL Server Compact still exists, whether or not it can be added to a NON web based project and if it will be easy to deploy and be easy to manage like an Access database was.
When I try to follow the directions to add SQL Server Compact to my project, it isn't available in the Data Source drop down list (there are "Simple by ErikEJ" versions listed but they don't seem to work) I have seen SQL Server Compact talked about with regards to web projects but I am building a locally installed .exe. I can't find ANY current info about what flavors of SQL are available right now to add to a local program running over a peer to peer network.
SQL Server Compact is no longer supported and developed by Microsoft, I suggest that you use SQL Server Express, it allows remote connections (if configured to allow it) and has modest resource requirements. Supports a database up to 10 GB of size.
As suggested, SQL Server CE can still be used but is no longer supported. For file-based databases, Microsoft currently recommend SQLite.
For a multi-user system, SQL Server Express is probably your best bet. It's still server-based though, so the server needs to be installed somewhere. For local databases, you can install on the same machine as the application and attach a data file on demand. For multiple clients, you'll need the server installed on a machine accessible to all and a permanently-attached database.

How to password protect database that is created using Entity Framework Code First?

The title says it all: as we are nearing release of our desktop application, which uses a local database (SQLServer 2014 LocalDb), we want to password protect access to it.
The database will be created using EF Code First on the user's computer the first time he starts up the application.
This must be really simple, but I seem to overlook the solutions that should present itself on Google.
The short answer here is you can't password protect LocalDb. LocalDb is designed to be a low friction database setup for development and testing, but it does not provide any of the advanced features of SQL or even SQL Compact Edition. From MSDN:
LocalDB is created specifically for developers. It is very easy to install and requires no management
and then there is this:
Moreover, if the simplicity (and limitations) of LocalDB fit the needs of the target application environment, developers can continue using it in production, as LocalDB makes a pretty good embedded database too
"pretty good" implies that while it will work, there may be better solutions. Essentially, the lack of security is a feature of LocalDB. It is designed to run as the currently logged in user, giving them full access.
If you need Database Security as a feature of your deployed application, but do not want to deal with the complexities of a full SQL installation, you should consider SQL Compact Edition.
See this article How to: Deploy a SQL Server Compact 4.0 Database with an Application. Deployment will vary depending on the deployment methods used by the rest of your application.
Entity Framework is an abstraction layer which is not specifically tied to a specific database technology. It will work identically with LocalDb, SQL Compact, SQL Express, MySQL, postgresql, etc... usually with nothing more than than the correct database driver and the correct connection string supplied.

How to roll an SQL Database (and subsequent updates) into a ClickOnce publish?

My application has a client that also uses a local SQL Server database. In the early stages, I want to use clickonce to propagate changes/updates to the app, but without the SQL Server definitions/tables/and in some cases data in the tables, the client will not work.
I will admit that I can't find much on how to use an SQL Server Project type in VS 2012... But that might not even be applicable.
If this is impossible, then am I forced to do some kind of whacky migration script dl'd via web service?
The ClickOnce works fine for the client, BTW, but obviously on any run on a client (other than my dev box, of course), it barfs...
I'm using EF6+, and on my dev box SQL Server 2012, but there is so little data on the client that I could use SQL Server Express, and make that a ClickOnce prerequisite... But again, how do you roll the DB into the update/install(er)?
I must be losing it, because there is precious little I can locate that addresses this seemingly common architecture for deployment...
We used to have Deployment Projects in VS...

Deploy application and database in WPF

I have a WPF application and it has a SQL Server database. All users of the application will be able to do the following:
Be able to install the application locally, and also the database (blank tables with no data) using a single click. Henceforth they will be able to run the application locally on their own machines. All the users have SQL Server installed on their machines.
Be able to get updates (or notification of updates) on the application and database, and will be able to install the updates if they choose to do so.
I realize that ClickOnce can do it for the application only. Now since I have the database along with the application, how can I do it?
Any help will be greatly appreciated.
If your users have the adequate permissions over their database (which I hope they have) you could simply check that the DB is ready at application Startup, and if not, run the creation scripts on it.
You can deploy an SQL Server compact database along with your application. Sample here: http://robindotnet.wordpress.com/2010/02/28/how-to-deploy-the-sqlserver-compact-edition-software-locally/
For SQL Server 2005 / 2008 the user must use the Microsoft provided installers.

Resources