Wednesday, March 28, 2012

how to create new login account in MS-SQL Server 2005 Express Edition?

Hi all,

I am new to MS SQL Server.
I have downloaded and installed SQL Server 2005 Express Edition.

I am just learning database programming with this.

But when I read MSDN documents - role, user-name, login-name confuses me.

I tried as following,
1. create database 'eg_database'
2. exec sp_addlogin 'eg_login', 'eg_loginpasswd', 'eg_database'
3. exec sp_adduser 'eg_login', 'eg_user'
after these 3 steps, I tried
sqlcmd -S .\SQLExpress -U 'eg_login'
I was asked for pass word and entered correctly. But I get error only.

Password: Msg 4064, Level 11, State 1, Server SYS1\SQLEXPRESS, Line 1
Cannot open user default database. Login failed.
Msg 18456, Level 14, State 1, Server SURASYS1\SQLEXPRESS, Line 1
Login failed for user 'eg_login'.

What I want to know is,
1. I want to create one new database
2. a new user account to access that database with table create, select, update, delete, alter, insert permission.
3. Any server permissions/configurations have to be done to access from another machine in network? or simply "sqlcmd -S sys1\SQLExpress -U username -P password " (how to specify IP address in this syntax instead system name(i.e. sys1).

pls guide me with steps to finish the above things.

Regards,
Purusothaman A
Finally I found answers for my questions 1 and 2 with the help of MS SQL Server Management Studio Express.

CREATE DATABASE [db1] ON PRIMARY
( NAME = N'db1', FILENAME = N'E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\db1.mdf' , SIZE = 2048KB , FILEGROWTH = 1024KB )
LOG ON
( NAME = N'db1_log', FILENAME = N'E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\db1_log.ldf' , SIZE = 1024KB , FILEGROWTH = 10%)
GO

USE [master]
GO
CREATE LOGIN [db1_user] WITH PASSWORD=N'db1_passwd', DEFAULT_DATABASE=[db1], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [db1]
GO
CREATE USER [db1_user] FOR LOGIN [db1_user]
GO

Still searching answer for question 3.

Regards,
Purusothaman A
sql

No comments:

Post a Comment