If you have not already created the accounts then first you will have to create account in sql server.
Steps to Create a new account to SQL server to connect with your windows account.
1. Right click on cmd.exe (Command Prompt) and click "Run as Administrator"
2. Write :
sqlcmd -S( is the sql server instance name. eg.: .\sqlexpress)
go
3. SQL server should now connected with administrative rights. Now you can create user account for logging in.
First create a SQL Server login for your domain account.
CREATE LOGIN [your domain account] FROM WINDOWS;
GO
your domain account has to be replaced with the domain account you want to add. For instance your domain is called darth and the user vader than it would be
CREATE LOGIN [darth\vader] FROM WINDOWS; GO;
To check if the login was successfully created type in
SELECT NAME FROM SYS.SERVER_PRINCIPALS
GO
and the domain user should appear in the result list.
Grant sysadmin rights
You can retrieve a list of server roles using the sp_helpsrvrole procedure. So to add the user to the sysadmin server role group type the following (example is still domain darth user vader)
SP_ADDSRVROLEMEMBER ‘darth\vader’, ‘sysadmin’
GO
Done.
Quit SQLCMD and command prompt and open again as domain user instance with your domain account. Type in select user_name() and the result should be dbo.
To Attach a Database File
1.Open the command prompt on the server.
2.From the command prompt, connect to an instance of SQL Server by using the following sqlcmd command:
sqlcmd -S Server\Instance
Where Server is the name of the computer and Instance is the name of the instance.
3.When connected, type the following commands:
USE [master]
GO
CREATE DATABASE [database_name] ON
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\.mdf' ),
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\.ldf' )
FOR ATTACH ;
GO
Where database_name is the name of the database you want to attach, FileName is the path and filename of the database file and the log file, and FOR ATTACH specifies that the database is created by attaching an existing set of operating system files.
4.To verify that the database has been attached, type the following two commands:
select name from sys.databases
go
5.The sqlcmd tool displays the names of all databases attached to this instance of SQL Server Express. In the list, you should see the database name you provided in step 3.
Steps to Create a new account to SQL server to connect with your windows account.
1. Right click on cmd.exe (Command Prompt) and click "Run as Administrator"
2. Write :
sqlcmd -S
go
3. SQL server should now connected with administrative rights. Now you can create user account for logging in.
First create a SQL Server login for your domain account.
CREATE LOGIN [your domain account] FROM WINDOWS;
GO
your domain account has to be replaced with the domain account you want to add. For instance your domain is called darth and the user vader than it would be
SELECT NAME FROM SYS.SERVER_PRINCIPALS
GO
and the domain user should appear in the result list.
Grant sysadmin rights
You can retrieve a list of server roles using the sp_helpsrvrole procedure. So to add the user to the sysadmin server role group type the following (example is still domain darth user vader)
SP_ADDSRVROLEMEMBER ‘darth\vader’, ‘sysadmin’
GO
Done.
Quit SQLCMD and command prompt and open again as domain user instance with your domain account. Type in select user_name() and the result should be dbo.
To Attach a Database File
1.Open the command prompt on the server.
2.From the command prompt, connect to an instance of SQL Server by using the following sqlcmd command:
sqlcmd -S Server\Instance
Where Server is the name of the computer and Instance is the name of the instance.
3.When connected, type the following commands:
USE [master]
GO
CREATE DATABASE [database_name] ON
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\
FOR ATTACH ;
GO
Where database_name is the name of the database you want to attach, FileName is the path and filename of the database file and the log file, and FOR ATTACH specifies that the database is created by attaching an existing set of operating system files.
4.To verify that the database has been attached, type the following two commands:
select name from sys.databases
go
5.The sqlcmd tool displays the names of all databases attached to this instance of SQL Server Express. In the list, you should see the database name you provided in step 3.
No comments:
Post a Comment