Sunday, February 19, 2012

distributing a database and creating a new user

Hi!
I'm new to trans-SQL. I wounder how I can add an user to newly created
database?
I've created a window-application that is using a SQL-database for reading
and storing data.
When I now want to distribute my application I also need to distrubute my
database.
Is the best way of distributing a database through trans-SQL?
Or should I create a new database on my localhost and distribute a backup?
the code I've so far is...
USE master
GO
CREATE DATABASE myTestDB
ON
(NAME = myTestDB_dat,
FILENAME= 'c:\program files\microsoft sql server\mssql\data\myTestDBdat.mdf'
,
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5)
GO
I would like to have an user called "testuser" with password "test"
please help.
Thanks in advanced
Best regards
- Hans -
--
(Have fun programming with ... C#)1. you can add a user using the sp_adduser stored proc
sp_adduser [ @.loginame = ] 'login'
[ , [ @.name_in_db = ] 'user' ]
[ , [ @.grpname = ] 'group' ]
2. or you use an exisiting windows nt account using the so addlogin
sp_adduser [ @.loginame = ] 'login'
[ , [ @.name_in_db = ] 'user' ]
[ , [ @.grpname = ] 'group' ]
3. you can also add a "users" table which contains userinformations such
as userid, name, lastname,etc and the password which you can be hashed using
md5 or sha1 technology of the.net .
In this way you can easily add, remove user or changed their password.
you can make the application or a stored proc to verify if the password is
corerct.
in this approach you will be using a single account to connect to sql server
.
will it will depends on you computing needs
hope it helps
"Hans [DiaGraphIT]" wrote:

> Hi!
> I'm new to trans-SQL. I wounder how I can add an user to newly created
> database?
> I've created a window-application that is using a SQL-database for reading
> and storing data.
> When I now want to distribute my application I also need to distrubute my
> database.
> Is the best way of distributing a database through trans-SQL?
> Or should I create a new database on my localhost and distribute a backup?
> the code I've so far is...
> USE master
> GO
> CREATE DATABASE myTestDB
> ON
> (NAME = myTestDB_dat,
> FILENAME= 'c:\program files\microsoft sql server\mssql\data\myTestDBdat.md
f',
> SIZE = 10,
> MAXSIZE = 50,
> FILEGROWTH = 5)
> GO
> I would like to have an user called "testuser" with password "test"
> please help.
> Thanks in advanced
> --
> Best regards
> - Hans -
> --
> (Have fun programming with ... C#)|||sorry got a little messed up. let me correct my self
for sql user
1. sp_addlogin
Creates a new Microsoft? SQL Server? login that allows a user to connect
to
an instance of SQL Server using SQL Server Authentication.
Syntax
sp_addlogin [ @.loginame = ] 'login'
[ , [ @.passwd = ] 'password' ]
[ , [ @.defdb = ] 'database' ]
[ , [ @.deflanguage = ] 'language' ]
[ , [ @.sid = ] sid ]
[ , [ @.encryptopt = ] 'encryption_option' ]
2. sp_grantlogin for windows account
sp_grantlogin [@.loginame =] 'login'
3. to allow SQL users to use the database you can use
sp_adduser/sp_grantdbaccess
4. to allow Nt users you can use
sp_grantdbaccess
"jose g. de jesus jr mcp, mcdba" wrote:
> 1. you can add a user using the sp_adduser stored proc
> sp_adduser [ @.loginame = ] 'login'
> [ , [ @.name_in_db = ] 'user' ]
> [ , [ @.grpname = ] 'group' ]
> 2. or you use an exisiting windows nt account using the so addlogin
> sp_adduser [ @.loginame = ] 'login'
> [ , [ @.name_in_db = ] 'user' ]
> [ , [ @.grpname = ] 'group' ]
> 3. you can also add a "users" table which contains userinformations such
> as userid, name, lastname,etc and the password which you can be hashed usi
ng
> md5 or sha1 technology of the.net .
> In this way you can easily add, remove user or changed their passwo
rd.
> you can make the application or a stored proc to verify if the password is
> corerct.
> in this approach you will be using a single account to connect to sql serv
er.
> will it will depends on you computing needs
> hope it helps
>
> "Hans [DiaGraphIT]" wrote:
>|||this made sense... Ill try it out first thing tomorrow morning
thank you
Best regards
- Hans -
--
(Have fun programming with ... C#)
"jose g. de jesus jr mcp, mcdba" wrote:
> sorry got a little messed up. let me correct my self
> for sql user
> 1. sp_addlogin
> Creates a new Microsoft? SQL Server? login that allows a user to connec
t to
> an instance of SQL Server using SQL Server Authentication.
> Syntax
> sp_addlogin [ @.loginame = ] 'login'
> [ , [ @.passwd = ] 'password' ]
> [ , [ @.defdb = ] 'database' ]
> [ , [ @.deflanguage = ] 'language' ]
> [ , [ @.sid = ] sid ]
> [ , [ @.encryptopt = ] 'encryption_option' ]
> 2. sp_grantlogin for windows account
> sp_grantlogin [@.loginame =] 'login'
> 3. to allow SQL users to use the database you can use
> sp_adduser/sp_grantdbaccess
> 4. to allow Nt users you can use
> sp_grantdbaccess
>
> "jose g. de jesus jr mcp, mcdba" wrote:
>

No comments:

Post a Comment