创建多个用户使用SQL Server Express的一个C#.NET WinForm应用程序 [英] creating multiple users for a c#.net winform application using sql server express

查看:144
本文介绍了创建多个用户使用SQL Server Express的一个C#.NET WinForm应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server Express的单个SQL数据库。

i have a single sql database in sql server express.

我有一个登录MAINLOGIN,这个数据库。

i have a login MAINLOGIN, for this database.

我想在该数据库中的数据的插入,通过多个用户,U1,U2,U3,每个具有不同的用户ID&放大器;密码。

i want insertion of data in this database through multiple users, U1,U2,U3, each having different userids & passwords.

这些用户将由MAINLOGIN创建手动或通过WinForm应用程序。

These users would be created by MAINLOGIN , manually or via the winform application.

因此,在创建MAINLOGIN,我会为他的权限进一步创造登录。

So while creating MAINLOGIN , i would give him permission to further create logins.

有关这是我应该做的?

我无法创建多个用户,因为对于一个数据库中,只有一个用户可以在一个登录。

i cannot create MULTIPLE users, because for one database, only one user can be created under one login.

所以我应该创建多个登录,L1,L2,L3,再图,U1 ,U2,U3他们。

so should i create multiple logins, L1,L2,L3, then map, U1, U2, U3 to them.

或者,是否有更好的方法来做到这一点?像应用程序角色等。

Or, is there a better way to do this? like application roles etc.

我不希望使用Windows身份验证。因为如果我知道系统密码,然后我可以简单地通过应用程序连接SQL插入错误的数据。

i dont want to use windows authentication. because if i know the system password, then i could simply connect sql via the application and insert wrong data.

推荐答案

在SQL服务器,您可以基于Windows帐户,或单独,特定的SQL帐户或者帐户。对于这两个变化,你需要的一个帐户需要使用你的数据库的每个用户

In SQL Server, you can have either accounts based on Windows accounts, or separate, specific SQL accounts. For both variations, you need one account for each user that needs to use your database.

唯一的例外是创建一个SQL的能力Windows安全保护的,例如服务器登录 MyAppUsers ,然后在你的数据库中该登录的用户。有了这一点,任何Windows帐户是安全组的成员(在Windows / AD)也将有权限查看/使用你的数据库。

The only exception is the ability to create a SQL Server Login for a Windows security group, e.g. MyAppUsers, and then a user in your database for that login. With this, any Windows account that is member of that security group (in Windows/AD) will also have permissions to see / use your database.

通过这种方法,你'重也感动谁可以使用你的数据库从SQL Server的,因为它真的只依赖于Windows安全组成员的管理。

With this approach, you're also moving the administration of who can use your database out of SQL Server, since it really only depends on membership in a Windows security group.

一登陆,一个用户 - 即得到与此权限的多个Windows帐户。 !似乎是一个赢家我

One login, one user - multiple Windows accounts that get permissions with this. Seems like a winner to me!

更新:

创建一个登录一个Windows AD组:

Create a login for a Windows AD group:

CREATE LOGIN [DOMAIN\GroupName] FROM WINDOWS

创建基于登录在你的数据库的用户:

Create a user in your database based on that login:

USE (your database)

CREATE USER GroupNameUser 
FOR LOGIN [DOMAIN\GroupName]

为您的SQL Server连接的连接字符串:

Connection string for your SQL Server connection:

server=(your server);database=(your database);integrated security=SSPI;



还有什么可以告诉你吗?

What else can I tell you?

更新#2:的代码的不可以使用Windows帐户是这样的:

Update #2: the code not using the Windows accounts is this:

创建一个登录每个用户需要使用你的应用程序

Create a login for each user that needs to use your application

CREATE LOGIN (some login name) WITH PASSWORD = 'Top$ecret'

创建基于登录在你的数据库中的用户您的应用程序的用户

Create a user in your database based on that login - again, once for each user of your app:

USE (your database)

CREATE USER UserName
FOR LOGIN (some login name)

连接您的SQL Server连接字符串:

Connection string for your SQL Server connection:

server=(your server);database=(your database);
  user id=UserName;Password=Top$ecret



但同样:这需要<强>登录一次,包括每个数据库中的密码和一个用户您需要跟踪的,可能做的东西一样,从你的数据库应用程序重置密码操作等。其它更多的管理开销方面!

But again: this requires one login including a password and one user in each database which you need to keep track of and possibly do stuff like "reset password" operations etc. from your database app. Lots more in terms of admin overhead!

这篇关于创建多个用户使用SQL Server Express的一个C#.NET WinForm应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆