I am creating an application for some user to maintain records in database. For this, I'll have to write SQL query (C#) and create the database, if does not exist, when user starts/installs the application. To make the creation and backup procedure easier, I want to create a separate file for SQL Server that will be used to store data. This file will be included in installation pack and copied to the destination folder to be used by SQL Server.
I've seen that we can create such file but never used like this.
Is it possible to accomplish the job I am trying to do?
i think that if each application have its own db you should use or SqlCe or SqlLite
They are a self-contained, serverless, zero-configuration, transactional SQL database engine.
So you don't have to install sql express on every pc.
They use a subset of tsql and you can do almost the same thing as sql server
you could embed a file in the application with all the sql command to create the db and then execute it the first time the application start.
Anyway you can distribute your app with the db already created and ready to use: it is just a .sdf file
If you think to distribute your app with clickonce than Sqlce is better becouse clickonce recognize its file format and handle it during the application updates
If you want to use SQL Server, you can use the Compact Edition: http://msdn.microsoft.com/en-us/data/ff687142
SQL Server CE databases are stored in .sdf files (up to 4GB) that can be shipped with your application. That way, if you want to connect to a full SQL Server database later, you could just change the connection strings in your application config.
You could make a backup and then restore it http://www.dotnetspider.com/forum/162986-database-backup-restore-through-C.aspx
Related
My C# .NET (4.5.2) application accesses a local SQL Server (13.0.1601) database.
For data archival purposes my client wants to pack a snapshot of the program and the database in a folder to run the old state when needed.
How can this be achieved with no running SQL Server service but only the folder contents and an installed .NET runtime?
Options considered so far are exporting the database to .bak or .csv and putting them in the folder, but those seem to involve a lot of manual labor.
As mentioned in the comments by marc, you need to have a SQL instance running to use a backup file.
Exporting it to a .bak file is not a "lot of work" - it just involves logging in to the SQL Server (from the application) and issuing the right SQL commands.
But in order to view this again you will have to re-import it back into a SQL instance - this is the reverse of the step above (although obviously you will have to rename it because your original database will still be resident in the SQL instance).
If you are looking to avoid having a SQL instance (service) installed then maybe SQL Server Express LocalDB is an option for you - it runs totally in memory.
You could create a script to export the tables as CSV and modify the program to use q to run its sql queries directly to those CSV files.
There is no embedded version of SQL Server. The closest thing is the LocalDB feature available since the 2012 version - it does require installation of some SQL Server components but does not require running a service. With it installed, you'd attach the MDF and LDF files (read-only if necessary) of the snapshot.
I have made a Wpf application and i am using linq to SQL classes also i have made my database in SQL server 2012 so is there any way that i can deploy my application in such a way that it will run on other PC's?
Check your app.config file. Make sure your connection string contains:
valid DataBase address
Valid credential for the db
As your update:
whenever i make setup file and run on another pc it give me exception
because sql server isnt installed on that pc
Either you need to deploy a database in internet, accessable by your app. Or you have to use an embedded sql db (e.g. add a db.mdf to your solution). I think this suit you better.
Is there a possibility to create and access Oracle Database files from anywhere in the file system? I want to connect with C# and Entity Framework or NHibernate.
Background is we need to create a folder in the filesystem which represent a project and contains
the database itself
a very complex file and folder structure
the user wants to copy the folder to a new PC, and work with this project
I know SQL Server compact supports such scenario but we need Oracle as DBMS.
No. Oracle has no feature like that. Database files are created on the database itself, and they aren't as portable as SQL Server database files.
I'm in a situation where I need to create a partial copy of a database from a remote SQL Server (2005/2008 Express Edition) and store it in a local SQL Server (2005/2008 Express Edition) database. The local copy will have the same schema definition, but contain only parts of the data from the remote database.
The local database has to be given a unique name with parameters from C# code, similar to
TodaysDate_SerialNumber_MachineNumber_DatabaseName
e.g. 20100622_1_3_DatabaseName
(Don't get caught up with the naming scheme, it hasn't been decided yet.)
I'm working in C# on .net 3.5 using VS2010.
My thoughts so far is to execute the create script for the database on the local SQL server from C# code, and then copy data from the remote database to the local database, filtered on what I actually need. The operations have to be started from C# code, but doesn't necessarily need to be all C# code. But I haven't decided yet. What do you think would be the best option for doing what I want to do?
(Btw, if I'm being unclear, just let me know and I will try to update the question with more info.)
SqlBulkCopy is probably your best bet if you're doing this entirely in code.
You'll have sql connections to each of your databases, then a select statement to run on your source database which will insert rows into a destination database/table.
The answer to this really depends on what you are most comfortable doing.
I'd probably set up a linked server on the local SQL Express and write a single SQL Script to do the whole thing. It could report progress back to the C# app using RAISERROR ... WITH NOWAIT and these messages can be processed asynchronously by setting up a SqlInfoMessageEventHandler
Maybe you can create a backup of the database, download it to the local machiene, create there a new, empty database and restore the backup to the empty database with option "override". After that you can delete those records you don't want to "copy".
You could use Microsoft SQL Management Studio to create the backup- and restore-scripts.
Currently my website is written in ASP.NET Webforms using a SQL Server database. I am planning to build a ASP.NET MVC application not because it's better but because I want to learn the technology. My question is more specific to the database. I can create the database and import my SQL table via the import feature of the web interface to the SQL database or I can use a "local" database MDF file. I like the idea of using a MDF file because it will be easier to backup and deal with. My website doesn't get a lot of traffic... matter of fact I could be the only user. :) Now here is the question.
How much of a performance hit will I get by using a local SQL Server MDF file instead for my database?
Effectively none. Or really none more than having the DB run on the same box as the web site. It is still a Sql Server Express database all the same. Production-wise, you probably want the DB running on a separate box dedicated to serving databases. But code-wise, the only difference will be your connection string.
SQL Server uses a MDF file for each database on its server. There is no difference between a MDF file and a 'database' because the 'database' gets stored in a MDF file anyway.
Performance wise you should not see a difference.
The biggest issue is with production deployment and management. It is MUCH easier to manage a standard database, than a dynamically attached .mdf.
Also, don't forget that your web host has to support this as well. And since SQL Server Express is the only SKU that supports "user instance" databases, the host will have to have Express installed for you to use it as-is. OTOH, you can develop with it this way and then just deploy your database and change the connection string when you deploy to the web host.
The only difference beyond the normal resource limits of the Express version of SQL Server is a negligable startup cost while the SQL Express engine connects to the MDF file, does its routine checks for file integrity and transaction log stuff.
This should only happen on application start up, not for every request.