How to put local -portable- database in c # (visual studio 2015, sql server compact)?

1

I was doing a system in , I had it connected to a database in access . But I realized that maybe I could not; Generate the installer of the program and pass it to another person. Someone told me to try to put a database of Sql Server Compact , so, I would not have to worry about putting a connection string like "C:/Users/NombreUsuario/BaseDeDatos.accdb" What I had to do was add my Sql Server Ce database to the project and put the connection string in App.config of the project. Add a database by clicking on the name of the project > add > "Service-based database". If I want to change the name, Visual Studio will generate it with the name DataBase1.mdf along with another file called DataBase1DataSet.xsd . But I really do not know how to do it. Try looking for some tutorials on youtube or in forums. But in many they use a reference to System.Data.SqlServerCe that I do not have and can not download from NuGet.

How can I do it? (Include local database and be able to put it in the project to generate the installer of the program and run it on any computer without server) Greetings and I hope I did not confuse you.

    
asked by DevAPI 08.06.2016 в 03:49
source

1 answer

3

> > thus, I would no longer have to worry about putting a connection string like "C: /Users/UserName/Database.accdb"

But with Ms Access you do not need to put a complete route if you need it.

If the accdb file is next to the .exe you can use the | DataDirectory | to refer to the db

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\BaseDeDatos.accdb;

Persist Security Info = False;

> > Visual Studio gave it the name DataBase1.mdf along with another file called DataBase1DataSet.xsd.

The .mdf extension is a Sql Server file, this would not be Sql Compact since the extension should be .sdf

Note: I did not find an image of VS2015, but the item should be similar to the image or at least the extension should be sdf

Maybe help this tool

SQL Server Compact / SQLite Toolbox

by means of this you could create and manage the db

Visual Studio 2015 Community SQL Server Compact 4.0

    
answered by 08.06.2016 в 13:01