Package a COM Ole Oject Library with database in C# - c#

I'm developing a Sql database module in C# and It's my first project in C# so it's really confused.
Now I exported to a dll file and have to registered it and create database by script manually. So are there any method that I can package it into a installation file that auto register object and create database? I've search but it only have a option publish in visual studio with Application, Not a Library.
Extra Question: I'm using visual studio 2015. My database is just local database and I read somewhere that Visual Studio have a local database format is SQL CE. But I find only template that create mdf database, and I think it's new local database format, isn't it?. I try to attach this file to Sql Management Studio in remote machine, but it seem like that this mdf file have some static link to my development computer path and it can't be attached. I've to switch to Server database, which is created from another SQL project and generate script to create database. So are there any method that I can deploy local database without script file? And is it that connect String is the same for all version?
My database is small So if it need to convert to other format, I think I could try.

Related

Create Backup of Attached SQL Server Project in Visual Studio

Good day!
I'm trying to create a standalone C# project with a SQL Server database attached so I only need to install a SQL Server Compact Edition.
I managed to connect to the said database and do some basic display, add and delete.
What I'm trying to do now is to have an option for the users to backup and restore the database.
Upon checking the files of the project, the tables and stored procs are in script format. Is it possible for it to be backed-up the same as how .mdf database files are backed-up and restored?
I am also open to suggestions on ways on how to easily have a standalone project be developed. So far this is only what I got. Thanks in advance guys!

how to publish c# database project

I have created a C# database project in Visual Studio 2010 and tried to publish as a normal project, but its not storing values in database. I have database file.mdf and connection string 'Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Users\fkr\documents\visual studio 2010\Projects\Management\Management\Mgt.mdf";Integrated Security=True;User Instance=True'
I am working with database for the first time and i'm not having any
idea about how to deal with it.
Please help...
You have to replicate your database from development machine to the server.
There is an option of publishing a database in Visual studio, steps for the same are:
Right click on the database and choose publish to provide that will present a dialog window to export your current database schema to a .sql format file which you have to import on the server to replicate the same database as of your development machine.
For more info refer this video: https://www.youtube.com/watch?v=T1LUrUJ2cnc

Creating an installer with C# application project,mysql server and ability to automatic restore database to MySQL server

I developed a C#.NET desktop application that uses MySQL as a back-end. What I want is that when user installs the application, the MySQL server should automatically installed and username and password are automatically set and the database is restored from a SQL Dump file automatically by the installer. I am using setup project in visual studio to create installer. Is it possible to perform this operation in an installer?? If yes then please tell how to perform these operations??
I'm afraid you can't unless your database server is MSSQL. Better create a separate installation between your application and the database server.
I fixed the issue like This
tack all the Backup of the MySql Data base
Created Console Utility which store the database in console Application
By Using Heat.exe added the Sql File And .Exe file to the Project (Wix)
Use the Custom Action Call the Exe Which Store the Database Backup
Delete the Exe and Sql File from the Install location

Connecting a client-Installed C# application to an exported SQL Server database

I'm very new to creating installers. This application needs to connect to a SQL Server database for it to be used. The tables of that database has rows which are needed by the application, so just reconstructing the database structure is not what is needed.
Can I just export the database as a .mdf file and connect from there?
Or do I need to install SQL Server Express on those computer as a prerequisite and attach the database from there? If so, how do I attach it on installation?
Or are there other ways to include a SQL Server database to an installer and be used by the installed app?
On the target machines you need to install SqlServer (express or standard).
You don't need any management application like Sql Server Management Studio.
Then you can attach your MDF to the database engine via connection string as this one
Server=.\SQLExpress;AttachDbFilename=c:\yourfolder\yourfile.mdf;Database=yourdatabase; Trusted_Connection=Yes;
The installation of SqlServer is not an easy task to do via custom installers.
If your application is not intended to be used outside of the local machine you could use LocalDB.
The install of this flavor of sqlserver is more easy.
Other alternative is:
Extract a sql script that rebuilds your database. (and provide a method to execute the script)
Export the data needed and execute a bulk insert to reinsert the data in the rebuilded database

Add *.mdf file to C# Project

I'm using Visual Studio 2005. I create a project, not Web Project, just Windows application.
I remember that Access Database File can be added into a project. I don't need connection to server, data can be retrieved. And I want to do the same thing with SQL Database file.
I did the following steps:
Right-click on project.
Choose Add An Existing Item
Browse for *.mdf file.
DataSource Config Wizard appears and it displays this Message
An error occurred while retrieving the information from the database:
Failed to generate a user instance of SQL Server due to a failure int starting the process for the user instance. The connection will be closed.
I need help to add mdf file into my project.
To start with, and MDF file can be read only by an instance of SQL Server. If you deploy MDFs, then your application must either connect to a SQL Server provided by your end-user during setup, or it must deploy its own instance, in the later case a SQL Server Express Edition instance. See How to: Install SQL Server Express. With Visual Studio 2008 you can add a prerequisite to your own application setup MSI, see "Installing" the SQL Server 2008 Express ClickOnce Bootstrapper for Visual Studio 2008 SP1.
A second issue is that, despite the wide belief of the contrary, distributing the MDF alone without the LDF can land you into a world of pain. You can end up distributing an inconsistent MDF that needs the LDF to finish recovery and get into a consistent state.
But a more serious issue is your plan to deploy binaries (MDFs) instead of scripts for database deployment. This is doomed to fail. As soon as you'll plan to release v. 1.1 of your application you'll face the non-trivial problem of how to replace the user MDF (which now contains data added by the user) with your new MDF. This is why is much much better to deploy upgrade scripts always, and forget about the MDF in your project.
You can read from an Access file (*.mdb) in your app without any other requirements because the core Jet engine used by Access is included as part of Windows — it's built in. Sql Server is not included as part of Windows, and so you cannot use an *.mdf file in your app unless Sql Server has been installed and you have appropriate permissions for it.
It is possible to distribute either Sql Server Express Edition or Sql Server Compact Edition (recommended) with your app. Another option is SqlLite, which has a fully-managed database engine available.
An .MDF is a sql server DB, not MS Access. MS access is .MDB. You cannot read an .MDF on its own. It needs a log file (.LDF) as well. If you attach it to your local instance, it will create a new one for you. You can then connect to that DB.
To solve deployement problem (Updated version of your .mdf file and Code), you can have a utility in your application which can create .xls file of every table(Backup your database) which you used in your application. Now you can easly import those .xls file in SQL Server and create new version of .mdf file and attach same file in latest code.Now new release of your app ready to deploye..!

Categories