VSTO: include database in Excel file or VSTO Add-In - database

Is it somehow possible to integrate a database in an VSTO project?
Due to the amount of data I have to switch to an proper database. The only issue is that the users got too accustomed on the Excel interface, I'm not that optimistic to make them accept a new interface.
In order avoid to manage two files I would like to have the database included/hidden in a Excel file.

VSTO has custom parts but it only supports XML. If you can store the database as XML, maybe by creating an object model and persisting that, you can use custom parts.
If you need to store a literal database file, you might need to do it somewhere on the filesystem outside a workbook. If you do that, you can access it the same way any other program would.

You can use SQL Server CE in your VSTO Add-In.
If you want to install it with the Add-In, you'll need to include the following dll files to the root directory of your project. This example is for SQL Server CE 3.5.
sqlceca35.dll
sqlcecompact35.dll
sqlceer35EN.dll
sqlceme35.dll
sqlceoledb35.dll
sqlceqp35.dll
sqlcese35.dll
Then update the properties for of the dlls as well as the database file to the following.
References:
MSDN Deploying SQL Server CE with a Clickonce application
Merge Replication with SQL Server Compact 3.5 SP2 and SQL Server 2014 and 2012
Microsoft SQL Server Compact 3.5 Service Pack 2 for Windows Desktop
SQL Server Compact Toolbox for Visual Studio

Related

How do Visual Studio 2013 Database Projects work with TFS online and EntityFramework code first migrations

Fairly long title, but hopefully self-explanatory!
I'm starting a new project in Visual Studio 2013 using Entity Framework 5.0 with code first migrations.
I've connected my project to TFS Online using git - I'm interested in trying TFS Online as it offers source control management for 5 free projects (similar to BitBucket) but with strong Visual Studio integration.
I've not used Database projects in Visual Studio 2013 and I've found little information for how this all fits together.
What I'm trying to acheive is to create a simple Visual Studio solution with 2 projects - one an MVC .NET project and the other a database project. My goal is that code first migrations will make the neccessary changes to the sql scripts in the database project (which are managed under git source control). My web.config points to a local .mdb file as my database which is what is updated when I run update-database in EF which is what I feel is the problem.
How can I point EF to use my database project for code migration, and subsequently how can I automatically build my development database into a local .mdb file when debugging my solution?
Entity Framework Code First is a way to manage your SQL Schema. The single source of the truth lives in your code base. Migrations adds a way to move from one version of the schema to another. The SQL schema is a by-product of the build process.
SQL Server Database projects are also a way to manage your SQL Schema. The single source of the truth lives in your SQL Server Database project. You can use schema compare to generate scripts that move from one version to another.
Given that these technologies overlap in their intent and functionality, it doesn't really make sense to use them together. When you're using entity Framework Code First, leverage Migrations when you can (and when the features are sufficient for your situation).
When you're unable to use Migrations, you could use SQL Server Database projects to manage the schema and keep them in source control.
Note:
You should consider installing the SQL Server Data Tools as a replacement for the SQL Server Database projects should you want to use these. The data tools are a more advanced version of these projects, even if they might require Visual Studio 2012 to run for now. I suspect a version for Visual Studio 2013 will be available when Visual Studio 2013 hits RTM

Tool for prepopulation SQL CE database

started recently a WP8 project which uses LINQ to SQL as data layer. I've finished modeling the needed domain classes and would like to populate my testing database on the emulator. I managed to download the created SDF file (ISETool.exe) my problem now: How to open this file? Are there some GUI tools to read/write this SQL CE database?
I'm using Visual Studio 2012 Express for Windows Phone - if this info is necessary.
Any hint is appreciated!
You can use my SQL Server Compact Toolbox, supports import from csv and SQL Server. See my blog for walkthrough.

How to migrate a Visual Studio 2012 ASP.Net MVC 4 project to use an SQL Server instance instead of a data file?

When I create a new ASP.Net MVC 4 project with Visual Studio 2012 it puts the data in an mdf file in the project directory.
What I would like to do at this point is to migrate the database to an SQL Server instance gently, keeping all the scaffold stuff provided by the ASP.Net MVC 4 project template (I mean user accounts management etc.)
What would be the right step-by-step way to do this?
How exactly should I change the connection string?
How should I authentify my application in SQL Server in production?
Sorry for a dumb question but I haven't dealt with ASP.Net applications before, in my previous experience (which was with WinForms) all the actual users had a separate SQL Server account and it was pretty straightforward.
The whole User Instance and AttachDbFileName= approach is flawed - at best! Visual Studio will be copying around the .mdf file and most likely, your INSERT works just fine - but you're just looking at the wrong .mdf file in the end!
The real solution in my opinion would be to
install SQL Server - Express (and you've already done that anyway) or any other edition
install SQL Server Management Studio (Express)
create your database in SSMS Express, give it a logical name (e.g. YourDatabase)
connect to it using its logical database name (given when you create it on the server) - and don't mess around with physical database files and user instances. In that case, your connection string would be something like:
Data Source=.\\SQLEXPRESS;Database=YourDatabase;User ID=AppUser;Pwd=Top$ecret
and everything else is exactly the same as before...
For deployment to production, you basically have a number of options:
create deployment SQL scripts yourself and have them executed using sqlcmd or any other useful SQL script runner
use a SQL diff tool like Red-Gate SQL Compare or even the built-in Visual Studio diff tool to determine difference between the database version installed at your client's site, and the new version, and create a single upgrade SQL script from that diff
use the Visual Studio Database Projects and let VS handle the upgrade scripts and deployments. VS database projects craft a model on top of your database - you basically only ever create the CREATE TABLE .... script and the VS tools figure out what needs to be altered, dropped, created fresh
if you're using Entity Framework code-first - look into using the EF code-first migrations to update your database from C# code
What I did is just move the mdf and log file and attach them via SQL Server management studio
The connectstring can be quite simple, something like:
<add name="DefaultConnection" connectionString="Server=YourServer;Initial Catalog=YourDatabaseName;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />

What .sdf files. How it is different from .mdf files. Does it work with linq to Sql?

I am playing with wpf and when i have created database it is created with the .sdf files. I want to know details of .sdf files. How it is different then the standard .mdf files
and will they support linq to sql? Because i am not able to use it with linq files.
An SDF file is a Sql Server Mobile file. It is also referred to as Sql Server compact. It is predominantly used in mobile development but recently more and more common in single user desktop developments as well.
Visual Studio 2008 does not support Linq to Sql for Sql Server Mobile but the Framework does. You can find out more on implementing this here
You can find more on Sql Server Mobile here. The link will also help explain the differences between this and Mdf's, used by Sql Server.
There is also an article on building a Linq to Sql model for Wpf using Sql Mobile/Compact here
One of the main differences between a Sdf and Mdf is that until recently an Mdf could not be opened and treated like a normal file, whereas an Sdf is accessed as a file. However in Visual Studio this concept was reproduced by allowing Sql Server Data files which dynamically attaches the Mdf to a Sql Server Express session.

How do you work with SQL Server CE and SQL Server 2008 Express?

I have installed:
Visual C# 2008 Express
Visual Web Developer 2008 Express
Visual Studio 2008
SQL Server 2008 Express
SQL Server Management Studio
In Visual C# 2008 Express, I can "Add Item" and create a "Local Database" (.sdf file) or a "Service Based Database" (.mdf file).
Visual Studio 2008 is the same as Visual C# 2008 for applications but in Websites, the only way I can create .sdf or .mdf files is via the Database Explorer.
In Visual Web Developer 2008 Express, however, I can "Add Item" and ONLY create a "SQL Server Database" (.mdf file). Even the Database Explorer doesn't offer to create a SQL CE database.
Questions:
why the discrepency between the applications, is this normal or did something go wrong with my installations?
I never "installed SQL CE", where did it come from and how is it that I am able to create .sdf file?
How do you work with these in projects on a day to day basis, do you use Visual Studio to edit the databases or do you use SQL Server Management Studio?
I believe only Professional and above may create MSSQL CE databases.
SQL CE is installed with 2008 studio, I was surprised to see it myself and didn't see an option to exclude it.
Personally I use VS 2008 to add items to my project databases. Since it's open anyway I just use it. It provides most of the same functionality as Management Studio. If I am doing separate database work, I usually do it in Management studio.
The CE databases are pretty useless. They have a limited sub-set of types and functions. They do not support views or stored procedures. Basically they only store tables; I haven't attempted to create foreign keys in them.
There is no way to rename tables or columns. You must create a new table.
Once you create your database it must be manually added to your project.
You cannot directly create a LINQ to SQL class in VS2008 on a CE database. You need to use the command line tool sqlmetal (called from .NET console) to create the class for you.
I've had issues where the Class created for a CE database didn't work like a class built for a regular SQL database. Because of this I abandoned using a CE database all together.
It would be nice if there was a reliable way to use Linq to SQL on SQLite databases. SQLite is a great self-contained database not requiring any type of external engine.
Sorry I don't have any performance statistics for an SQL CE database.
I hope this is somewhat helpful.
Brett
Ok registered now and not sure why got a -1 vote on previous answer but will expand.
Web Developer Express 2008 Does not create or work with Sql Server CE simply because SQL Server CE is not designed to work on the Web Server.
When you load c# express or vb express. sql server express 2008 is offered to be installed. SQL CE isn't installed. if you go and add a data source the two I know will be there, Microsoft SQL Server Compact 3.5 (.NET Framework Data Provider for Microsoft SQL Server Compact 3.5)and Microsoft SQL Server Database File (SqlClient), the access client may be there also.
It should be noted with a default Express setup that if you choose to use the data provider for sql server compact it will fail even though it is an option. you would have to download sql server ce separately to create sdf databases.
Also Express versions are targeted to a different audience and doesn't have the same ui setup as the main vs sku's have. For example Web express in database setup doesn't even offer the choice to use sql server ce. while in VS it is a choice from the data menu mainly because VS supports more than just web developer.
Now you said you loaded VS 2008 (didn't say what version but doesn't matter since this affects standard and above)
The default install for vs 2008 will install Sql server ce (and as previous answer stated 3.1 was with rtm, 3.5 was with sp1). you can turn it off in advance options.
One concern I have is that you mention that you can't create a database in vs on web projects. which template are you using. You should be able to create server based database Items in add item and both local and server database objects in the data tab.
so in Summery.
on client based express skus and client based projects you should be able to create a local or server based database from add item and from the data tab.
Since sql CE is not officially supported on the Web Server. on the web skus in add Item you should only have access to create a server based database. on express since it is a dedicated sku CE isn't an option in either the data tab or the add item. on vs you can create a CE database from the Data tab. and you should have access to create a server database in add item.
sql server management studio doesn't care where the source is. so it will work with all and create the database.
I use all the options listed just depending on what or where I am at the time. as was mentioned CE on the desktop is primarily a cache database perfect for offline database support. but does have its limitations and in addition really needs better integration. once I am created or working with a database in support I primarily use management studio.
The key point in why you can't access CE from Web express is that CE is not supported on the web server.
Douglas
This is normal. The database types supported by the Visual Studio designer differ by edition. Note that any version of Visual Studio can write and use code that connects to any of those databases. It's just that the visual "wizard" tools included with the IDE that walk you through it are different for each edition.
SQL CE is the Compact Edition of sql server. It's intended for use on portable devices like smart phones or as an Access replacement for a local data store in desktop apps. It's very portable: only 2 dlls that clock in at less than 1Mb of disk space, and was probably included with at least one of your Visual Studio packages, probably all of them.
I normally do all my database work from Management Studio, but that's a personal preference.
The discrepancy is odd, but since SQL CE is a plugged-in item, it may well be that the team didn't test every possible scenario and some of the applications simply didn't get the info they needed to know that it's there. I'm not saying that anything went wrong - it may simply be a scenario that the SQL CE team never tested.
SQL CE was installed with Studio (can't recall offhand, but I think 3.1 shipped with the RTM and 3.5 shipped with SP1).
I always use Management Studio for making database modifications (except those done directly in code).

Resources