Visual Studio: Sql Server in-project DB - c#

I would like to create a new VisualStudio project with a simple SQL server db, but i want it to be portable, because several people will need to have access to the DB.
So it should be also accessible from a user with password.
The point is that when i create a Local SQL server DB i can't create a new user because it sais You can only create a user with password in a contained DB.
Is there a way to create a Local DB with password or a way to let several user access to the same DB?
Thx

Is there a way to create a Local DB with password
Yes. I'd recommend using Sql Server CE or SqlLite for a database like this. If you're only using Sql Server as a data store on the local machine, Sql Server, even Express Edition, which is still the full Sql Server engine, is usually way overkill for this. The full Sql Server engine really only makes sense when the database engine is the sole, exclusive reason that the machine where it runs exists.
Is there... a way to let several user access to the same DB?
Yes. Install Sql Server on a dedicated database machine, instead of using a Local DB, and set the appropriate connection string and permissions.
Here's the trick: you can't do both, at least not without going through all the same trouble you'd go through setting up a real Sql Server to run on the machine where this will be installed.

Related

C# SQL Server: Application works with database from another pc

I have my application written in C#, it uses a SQL Server database. I have a connection to a database in my C# code, some queries to write/read from database.
Now consider following: if I want to run this app from another PC, this PC has no SQL Server, will this app work? (I assume not) If not then how can this another PC still work with database? Is there a way to programmatically create database on another PC using C# so it has a name I need, columns I need. I created my database using SQL Server Management Studio.
I guess your application works with a local server.
First of all you should check in your application at startup if there is any local mssql server running. If not, you should handle it by installing one programmatically.
Read this answer how to do this if you don't know it.
After that you have to create the database, it's tables, maybe adding user priviliges. Write a SQL script that gets started by a class that starts it.
Read this to see how to start a SQL script in C#
You can do this by setting up SQL server on another machine (server).
Set that servers authentication to SQL Server authentication (requires username and password for that SQL server Management Studio)
Change the connection string in web/App.config from your C# app to use that servers Ip address and Credentails for SQL server

How to protect SqlLocalDB database file with custom password

I have designed a software using SqlLocalDb v11.0 instance. The database will be on user's machine (.mdf file). I was using SQL Server CE before.
In SQL Server CE my database is protected by a password with "Encryption Mode = Engine Default"
Is there any way to protect SqlLocalDB?
I know there is a way using named instances, as in the link
https://msdn.microsoft.com/en-us/library/hh510202(v=sql.110).aspx
Is there any way to associate password with LocalDB .mdf file. So that any other can not open it?
If you mean protecting files from user, I think the answer is No, you can't. a user can copy your files simply.
LocalDB always runs under the users security context; that is, LocalDB
never runs with credentials from the local Administrator’s group. This
means that all database files used by a LocalDB instance must be
accessible using the owning user’s Windows account, without
considering membership in the local Administrators group.
For more information see Permissions section in SQL Server 2012 Express LocalDB
I believe you have the option to encrypt and decrypt data using .Net Framework and TSQL methods, but you can't protect your database objects using database encryption options since TDE (Transparent Data Encryption) is not supported by LocalDB.
If you are willing to consider a third party product that may help you (there may be others) you may want to look at NetLib Encryptionizer. It it similar to SQL Server TDE but works on all versions and editions of SQL Server, including Express and LocalDB. Typically used by application developers. However it works differently than SQL's built-in TDE. SQL TDE is (obviously) built into SQL Server and encrypts on the page level. Encryptionizer sits between SQL and the operating system and encrypts on the file level.
There is another product, DBEncrypt I believe, but I am not sure about supporting LocalDB. It works by injecting code into the running SQL process.
(Disclaimer: I am from NetLib Security).

Easy way to keep two SQL Servers synced if you have read only access to publisher (source) of data

I am making C# app that rely on data from one old SQL Server 2005 machine.
Since I have only acces to read only data from that server, I need to build up some kind of handmade replication.
My app is going to use SQL Server 2012 and I am planing to read data from old SQL server in nightly tasks.
Before I start reinventing the well for sync data between two SQL Servers, I'll love to try to find some kind of library or system which can do the JOB.
Unfortunately I can't just setup replication between two SQL Servers because source of data is at SQL Server 2005 version and I do not have admin rights on that server.
I just need few tables to keep sync (updated) at my new SQL Server.
Is there some kind of embedded replication which can be called from code, and which have no needs for writing and admin access to publisher database?

Simple security for SQL Server LocalDB for local Windows application

A simple C# windows form application that uses a local SQL Server LocalDB (.mdf).
I want the end user to install the SQL LocalDB and application and run it in that simple, but also want the DB to be secured with a password (Like the one that is used on SQL Compact (sdf)).
I couldn't find that option in (mdf DBs) without creating a login in the server that should be identical to the one in the connection string! Which is not user friendly!
Need help! thanks :)

SQL Server Express Database hosted on Network Share - Is it Possible?

I've started work on a project that requires an SQL Server Database. I will be building a front end application in c# .Net 3.5, that will use LINQ to SQL.
I need to host the database on a network share so that a group of users can all gain access to the database, mainly for read only.
I know that SQL Server Compact is designed to run on the local machine and my company is not willing to front the costs of a full blooded SQL Server.
Is there a way of achieving what I need to do via SQL Server Express?
If so, which are the best guides on how to set this up?
Thanks
If you go with the (free) SQL Server express, it will do what you need - but you don't access it thru a network shared drive - the server would be located by an ip address (or equivalent DNS).
You c# application would be talking to a service - SQL Server - not reading to/from a database file. The service will handle the interaction with the database. Only the SQL Server service will need to know where the file actually is - your client machines won't know and shouldn't care.
If your background is only with file-based databases - i.e. MS Access, you need to change your mindset a bit about how SQL server works.
You can install a SQL Server Express instance and install the SQL Management Studio Express for all users who need access to the database. The Express Edition is a standard SQL server with limitations regarding the number of processors used, the maximum amount of memory used and the maximum database size. If these limitations don't bother you, it should work fine for you.
Using a network share as a database storage to access db files from several clients is a bad idea, as the sql server instance should always be the only one directly accessing the database, both for read and write access. Configuring several instances of SQL Server to access the same database will probably not work - and if it works, it will probably create havoc in your database files.

Categories