C# SQL Server data storage - c#

I'm writing an application in c# that uses SQL Server database for storage propose.
My question might be a bit silly, but yet I don't understand something..
I use a lot of application that use SQL Server for storage, but it looks like the DB is inside the application and installed in the installation process.
Does every time I use my SQL Server db in my application I need to install a SQL Server in my client's computer ?
Or can I somehow wrap my database in the installation ?
It looks a bit weird to me that a SQL Server must be installed in every computer I want to install the application on - although it uses a very simple database.
Maybe the solution is to use some other storage option ?

You can use a database like SQL Server CE or SQLite which doesn't require installing a server. It is just a single database file that is included with your program.

In teory you have to install only the client, but it is already installed in every Windows... You have just to config it. Run cliconfg on the command line. On 64 bit you have to choose which version (32 or 64 bit) to run

Usual practice for this kind of scenario is to provide user interface that would allow the client to enter server name and credentials with enough privileges.
I wouldn’t create an application that would automatically install SQL Server on client’s computer because that’s too intrusive.
Just provide a nice and clean user interface in the installation process and your clients will be able to do the rest.
Yes, there are options for SQL Server Compact Edition and other similar stuff but you’ll also have a ton of restrictions with these versions.

Related

Detecting and installing SQL Server Express with UWP app

I have written an UWP app for managing employees, timesheets etc.
How do I detect if SQL Server Express is installed and if not installed how do I setup SQL Server Express on the client computer? Is it possible to do it without running the exe file in 'fulltrust'?
I would also like to include the setup files in my app package with the configuration file to run a silent install on the client computer.
I have looked for a answer on many pages but could not find a real straight forward answer.
Some help here would be much appreciated.
when you have access to your client computer, you can run a check program in your setup process via checking if MS SQL Server Express registry key exists or not. If it exists, then it is installed.
Read this doc from Microsoft, there is a code snippet in the doc you can use:
https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2005/express-administrator/bb264562(v=sql.90)?redirectedfrom=MSDN
What do you mean by 'auto-detect' MS SQL Server Express installed'? Not sure what's your use case here.
Normally, you can not auto detect database to use since in many cases there could be multiple databases installed in the environment, and you don't know which one is the right one you are going to use. You have to know which database you are going to use first.
However, if you insist to detect database, you can do the port scan in your network which is really not a good idea.
So guess maybe your use case is unique.

C# connect to MSSQL .mdf DB without Server

How can I ran x86 .net 3.5 Windows Forms app with .mdf database on the computer without SQL Server (for example, XP of common user).
I have found few samples of connection strings, but all of them are contains something like Data Source=.\SQLEXPRESS
Doubt, that user will be having SQLEXPRESS on his computer. I want something like work with Access db - so user could work without even knowing, what's server, only with local file
MSSQL I have chosen instead of Access, because in the future I can add publish DB on server, but not now.
Maybe, I should use SQLLite, but how in that case?
Thanks.
How can I ran x86 .net 3.5 Windows Forms app with .mdf database on the computer without SQL Server?
This question has very simple answer - you can't!
You must distribute and install some version/edition of SQL Server with your application, otherwise the .mdf file will be nothing more than waste of disk space. You can install SQL Server along with your app. For more information you can see Install SQL Server from the Command Prompt and Install SQL Server using a configuration file. If this is a simple app working locally on a single workstation, you may want to consider using SQL Server Express LocalDB.
Another option is to use different database engine, which has easier deployment and embedding - SQLite, Firebird Embedded, etc. Pick one that you like. Most of these solutions require only to distribute one DLL/assembly with your application. You will not get the full power of SQL Server, but for most apps, it isn't needed anyway.

Database to use when creating an installer for your c# application

I am creating a c# application which requires to use a database and i am also planning to create an installer for my application. I just want to ask which database would be best to use in my application and how do i install it on a user machine while installing my application through installer file.
I have thought of using MYSQL database but for that u need to have MYSQL installed.
Update
i want each user to have there own instance of database when they install the application
You do not have to ship a full database server with your application; only the redistributable runtime which your application would use to connect to the actual database server remotely. In the case of MySQL, you only need the assemblies.
Applications I wrote relied heavily on SQL Server. In order to simplify evaluations and the initial deployment, the installer would install SQL Server Express (installed as an application specific instance). This is an approach I'd recommend if your application is intended to a centralised database.
What is key to understand, especially with commercial application, is that the database engine you install may have to co-exist with existing versions of the respective database engine. That is why application specific instances was created for SQL Server Express.
The alternatives, which are embedded, are:
SQLite.net
SQL Server Compact Edition. The deployment process is well defined.
VistaDB
Embedded databases have some challenges when deployed as part of a server application. For many years, Microsoft refused to allow SQL Server Compact Edition to be used for ASP.NET applications. If the database is per user, per device, an embedded database may be perfect.
Also be aware that MySQL has license restrictions when shipped as part of commercial software (aka you're acting as an OEM, ISV or VAR).
Have a look at SQL Server Express Edition.
It's just a file which you can copy and a class library which allows to access it. And after you finished your installation you can just delete the files (or to keep them if you need them to uninstall the product).
may be u are a fresh.
MYSQL is ok ,but u are creating a C# application,i strongly advise you use mssql
because C# has a close relationship with mssql,develop more convenient.
My advice would be using SQL Azure.
But only if:
You don't need much storage (<1GB).
You don't save sensitive Data there.
Your users have an internet connection.
It's a cloud based Sql Server Database. And the Conneciton is very simple, basically you connect like to any other Database via the Connection String.
www.windowsazure.com

How to use database without installing it?

I have a database in SQL Server 2008. I want to deploy my software with CD.
I want to give end user 2 choices :Use from CD and install it.
When end user selects the "Use from CD", I don't want install program.
How can I do program execution without installing?
Please help me about this problem
Thank you for your attention.
The program is coded In C# in MS visual studio 2010.Database Management system is MS Sql Server 2008
Use an embedded database which requires no setup and in-process execution, in your case best option is probably SQL Server Compact Edition
Edit: I know there are also other alternatives like BrekleyDb or SQLite but since Atayi is using SQL Server right now for his database, I suggested SQL Server Compact Edition to avoid any issue and stay on essentially the same technology/platform.
Please help me about this problem
Don't use the technology you selected.
This is like saying "I want to drive a ferrari, but one that uses no fuel". Engines use fuel. SQL Server requires installation.
Alternative is SQL Server CE which you can load into the process.
THat is it. Run from CD is not possible without having SQL Server installed if you use SQL Server. Arguing wont change that.
First of all, I don't know if SQL Server '08 exists as a portable version, but if it burned on a cd, the use of a database is not there. The burned files cannot be changed :-)
A portable DBMS is SQLLite, there are bindings for C# :-)
You can "Silent Install " Sql server also, that way the client will not be bothered by the configuration of the server.
When running from CD - change database back-end - use simple Microsoft Access Db file with ADO ODBC connection. In such case - you will have almost same SQL language and no need to install something for access db (huh, maybe general odbc drivers if they not exists).
When running from HD - switch db backend to full-scale MS SQL server ...

I'm trying to grasp the concept of creating a program that uses a SQL Server database, but I'm used to running it only on my local machine

How can I make a program use a SQL Server database, and have that program work on whatever computer it's installed on.
If you've been following my string of questions today, you'd know that I'm making an open source and free Help Desk suite for small and medium businesses.
The client application.
The client application is a Windows Forms app. On installation and first launch on every client machine, it'll ask for the address of the main Help Desk server.
The server.
Here I plan to handle all incoming help requests, show them to the IT guys, and provide WCF services for the Client application to consume.
My dilemma lies in that, I know how to make the program run on my local machine; but I'm really stumped on how to make this work for everyone who wants to download and install the server bit on their Windows Server.
Would I have to make an SQL Script and have it run on the MS SQL server when a user wants to install the 'server' application?
Many thanks to all for your valuable time and effort to teach me. It's really really appreciated. :)
Edit:
To clarify, each business will have their server completely separate from me. I will have no access whatsoever to them nor will they be in any way connected to me. (I don't know why I should clarify this :P )
So, assuming the have ABSOLUTELY NO DATABASE SERVER installed; what can I do?
Ok, part of the answer, dealing with the SQL Server Database (and frankly SQL Server Express will take you a long way - 4Gb of data) and the server install elements.
Firstly make installation of the SQL an SEP, make it a pre-requisite possibly tweak your installers to test (challenging) but substantially point them at the links to SQL Server express and let them get on with it).
Secondly separate installers, as suggested, for your client and your server elements.
Finally, how to build the database - I'd suggest using code to create and maintain (update) the schema i.e. once you have a connection to a server you can run code that calls DDL that does what is necessary (something like suggested here: How to create "embedded" SQL 2008 database file if it doesn't exist?)
A question - are you intending all communications from the clients to go through you WCF service?
Your install application should:
Obtain a SQL Server name, a username (with apprpriate rights to create a database) and password.
Either run SQL scripts using the locally installed command line tool or from code using SMO (for instance), against the user supplied server with the supplied credentials.
BTW, Before you expend effort writing an open-source help desk, have you checked what is already available? Also, Open Source Helpdesk
It is not so straightforward to deploy a client/server solution with an automatic installation.
You probably would then be better off to deploy your server installation together with a database engine and a skeleton database already setup according to your wishes. This is to avoid tampering too much with the existing server - who knows whats on it.
Also you say you want to install WCF services, well this would probably mean installing them on a customer server, in theory this shouldn't be a problem however in reality it could be, depending on what is previously on the server.
Do you want a single SQL Server instance running on your machine, or one on each of your customers' servers? If it's the latter, you'll want to install a SQL Server instance - anything from the (free, but limited and not open-source) SQL Server Express to a more expensive SKU - on each server. You can include this step in your server installation package; MSI installs make it very easy to bundle a MSSQL install.
Then you'll need to drop a schema, and maybe data, on the instance. You could do this as a step in your installer, or as part of your application setup process. It possible that a SQL Server instance, or more than one, might already be installed on the server, and your post-install step should allow the user to specify which instance on which to install your pieces.
Then, include a database configuration piece in your client application. Ask the user - or take from a configuration file at client install time, to allow for unattended or unprompted client installs - server connection details, like server name and authentication information.
A word on authentication - since you appear to be building Windows-based tools, use Windows integrated (domain-managed) authentication if at all possible. Don't get in the business of storing logins, but instead rely on the existing domain to manage logins. A good strategy is to use active directory groups to manage access. Grant access to a particular group in SQL Server, and defer group membership to Active Directory itself. If you can't gain the access necessary to do this, then grant permissions to AD user accounts themselves. Avoid creating SQL Server logins, the use of which open the door to some possible security problems.
I understand what you are trying to do. If I were you, I'd do the following:
Provide 2 downloads - 1 for client and 1 for server.
Forget about MS SQL Server and perhaps go with MySQL, since it really is open source. You could probably get away with using MS SQL Server Express Edition, but if your data set gets gigantic large (which is common with help desk databases), you'd be stuck.
As other people pointed out, on very first run (or at setup time), I'd have the client app locate the server.

Categories