SQL Server CE distribution - c#

I have spent several days trying to solve this problem with no luck and my requirements are really simple - I want to make an application with database which will work on most PCs (without DB server installed) and I want to use LINQ. For the compatibility reasons I want to use .NET framework 3.5 (every Windows 7 machine has it).
I have tried 2 ways: SQL Server CE and SQLite.
SQL Server CE
Although Visual Studio does not support LINQ for Compact Version of SQL server, I have found simple workaround - generating .dbml file using metal.exe tool from Visual Studio and then dragging it into project. My application works fine on my machine, but when I copy it somewhere else, it crashes. I have copied all dlls from C:\Program Files (x86)\Microsoft SQL Server Compact Edition\3.5 and tried 4.0 too. I think problem is that my app is not looking for dlls (references) inside its directory. I managed to get it work using DataSets (without LINQ), where I manually add reference to SQLServerCE and check CopyLocal to true. BUT when I use LINQ, there is no reference to SQLServerCE in project references and it is working. I don't know how to change it. Or is there a problem somewhere else?
SQLite
After long messing with SQL Server CE, I have tried SQLite. I am very disappointed how poor is SQLite support in .NET. I had to download older version of ADO.NET provider (newer versions does not add SQLite Database into my Visual Studio 2010 - I don't understand why but I googled that it is normal and I have to install old version and then replace it with newer). Then I downloaded dblinq (I have discovered that this project is dead later) and after some messing with dbmetal and dlls I get rid of errors in Visual Studio and compiled my application. But I can't run it, it always crashes on error 40 - like there was no SQLite server. Of course I have copied all dlls. I can't run it even on my development machine.
I am very surprised that it is nearly impossible to create simple database application in C# .NET which will not bother client with servers etc.
Please is there anyone who made SQL CE work with LINQ and mainly who made his app distributable?

I would suggest you try using the nuget Entity Framework for SQL CE package. It will download all the required assemblies to make it work.
http://nuget.org/packages/EntityFramework.SqlServerCompact/

Related

DTS.dll not registering properly in C# ASP.Net Visual Studio 2008 project

I've inherited an application from a former co-worker. It's a C# ASP.Net Web Application. When I try to compile it in Visual Studio 2008, it complains that it can't find the DTS namespace. So I added the DTS.dll file to References from C:\Program Files\Microsoft SQL Server\100\DTS\Binn. When I do that, all compile errors go away, but I get two warnings that look pretty nasty to me:
"Cannot find wrapper assembly for the type library DTSLib. Verify that (1) the COM component is registered correctly and (2) your target platform is the same as the bitness of the COM component. For example, if the COM component is 32-bit, your target platform cannot be 64-bit."
and
"The referenced component DTSLib could not be found"
Also, DTSLib in the References in Solution Explorer has a yellow exclamation point next to it.
First, am I correct to be concerned about this? Second, if so, how do I solve it? It's not a question of the bitness, since I'm working on a 64-bit machine and took the dll from Program Files, not Program Files (x86).
#Melanie: DTS has a some support issues in 2008, due to the creation of SQL Server Integration Services. https://msdn.microsoft.com/en-us/library/bb500440%28v=sql.105%29.aspx?f=255&MSPPError=-2147217396
I hope the support issues have been ironed out if the client is also on SQL Server 2008 R2.
What the most likely problem is is you do not have the packages fully installed. This is rather easy and handled by following the instructions at https://msdn.microsoft.com/en-us/library/ms143755(v=sql.105).aspx - essentially a backward compatibility "hack".
The problem may be the failure to register some COM components, which may or may not exist on drive. Most likely do, as you can follow the instructions above, but they may also be copied and registered at the time.
The reason I asked which version is you would have had to do a repair if they were still on a version like SQL Server 2000.
I would recommend the company invest some time in updating to SSIS, as they are not going to be able to migrate to SQL Server 2012 or 2014 if they still wish to do DTS. It was deprecated in SQL Server 2005, support reduced further in 2008 (with some limitations) and gone as of SQL Server 2012. Actually, there is a hack they might be able to do, but I have not tested it (and do not recommend it, if so).

including databases and .net with software

When I build my software, is it possible for me to incorporate everything from the solution with the software installer (perhaps using InstallSheild?)
The software I am writing at the moment uses a database with SQL, and is written in C# 5.0, so how would I install the database, SQL, C#, .NET etc. onto my clients computer when installing the software?
Yes, you can do that with an installer. InstallShield would do it but is quite pricey. Wix Toolset would do it and it's free, but it's not the friendliest installer I ever worked with (though it does work very well once you get the hang of it).
Both of those allow pretty straightforward installation of the .NET framework. You will need to work a bit at getting SQL installed.
While you could install SQL Server Full or Express this way it would be MUCH easier to use SQL Compact. I can't remember the license, but I'm pretty sure you can deploy the SQL Compact DLLs with your project and don't need to actually install it.
Yes you can deploy SQL database and the .Net frame work with your installation package. You could achieve this with Windows Installer as well.
Deploying Sql database with MSI
You have to first add your sql script file with your msi package script should have necessary steps to create database schema when its being executed on the SQL database. You can use SMO(Sql server Management Object) library to execute this script content on sql database. Check my other thread where I have posted working method to read the file content and execute on SQL database to create the database during deployment.
Execute sql script on SQL server using C#
Deploying .Net Frameowrk
Go to MSI Project > Properties > Prerequisites > Download prerequsites from the same location as my computer.
When you build you MSI project with this configuration your will get an extra exe file dotNetFx40_Full_x86_x64.exe which can deploy .Net framework on client machaines. You can execute this MSI when your application being installed.

C#: Create a DB using sql file in setup project

I am building a desktop application where it uses a local database file (.mdf). Since I was developing it on my machine I used SQL Management 2008 R2 SP2. Then I sent it out to others for feedback. But unfortunately they were not able to use it as they didn't have SP2 installed.
So, as a resolution, I want to include a sql file that would run while installing the application. I was wondering if someone could direct me how to do so.
What I have and what I think should be done is:
- Main Project (includes forms and classes - I have this working already)
- Setup Project (includes msi file that checks database existence and runs sql file accordingly - I need help on this)
I suggest you using wix to create the msi.
You know, you can no longer create setup project using visual studio (Version 2012 above). It has been removed completely.
So you should consider going in WIX (Windows Intaller XML) direction.
If you like the idea here is the quick and easy solution:
http://www.codeproject.com/Articles/331368/WIXDataBase
http://wix.tramontana.co.hu/tutorial/sql/creating-a-database
But its completely up to you to think about the alternatives.

Can't use SQL Server CE in VS2012

I'm developing a web application and was trying to use a local database file to store some information. However, when I add the .sdf file, I get an error. Below are some screenshots detailing my problem.
I've been trying to figure what's wrong for several hours. I've seen similar issues, but have yet to find a fix. I used to be able to use SqlServerCe connections before with .sdf files, though that was a different development environment. I have tried reinstalling everything SQL several times, including downloading everything I could find on MSDN. Can anyone help me out?
Below is my Solution Explorer View. I've just added Database1.sdf to the project.
I get an error as soon as I add it:
If I try to open the .sdf file, I get this error:
Here is my list of references:
And, finally, all of the relevant SQL-related installations on my local machine:
SQL Server Compact 4.0 is supported by VS 2012, but requires the DDEX provider to be properly isntalled. Sounds like your VS install is somehow broken. You can install my Toolbox add-in, and go to the About dialog in the Toolbox to check if the DDEX provider and SQL Server CE 4.0 is properly installed.

How to create an SQL Compact 2008 application

How can I make a SQL Compact 2008 application for the desktop? I know how to connect to a .SDF file with SQL Management Studio 2008, but I can't figure out how to connect to it with my app. I have seen tutorials about this and I can see in the C# code they are referencing some special namespaces, but I can't seem to get it to work. What I did is download the Microsoft SQL Compact SDK but I get an error whenever I try to add references to any of the DLL's that came with it. Does anyone know where I can find the correct binaries for this.
Have you gone here and downloaded all the components listed (including the design tools)?
If you post the "error" you get it might be easier to diagnose your problem.
You need to download SQL Sever Compact 3.5.
Then you could create a LINQ2SQL model (dbml) using the sqlmetal tool that
comes with the .NET SDK (and Visual Studio). Currently it is not possible
to create LINQ2SQL classes for the compact framework inside Visual Studio,
but you will be able to view and edit them.
I haven't got much time now, as I really need to get going,
but I hope this gets you started.
PS: References in my project are System.Data, System.Data.Linq
and System.Data.DataSetExtensions
UPDATE:
As for the DLL's you are referencing... I don't think they are .NET assemblies
but native win32 DLL's intended to be used by C++ developers.

Categories