Solved

Create Login script to the server

Posted on 2008-10-15
5
3,383 Views
Last Modified: 2008-10-15
I am trrying to create logins to a few database servers, i tried two scripts, some of them work on  a particualr server while the second works on some servers.

here are the scripts

USE [master]
GO
if not exists(select * from sys.server_principals where name = ABC\apps_dev')
begin
      CREATE LOGIN [ABC\apps_dev] FROM WINDOWS
end
GO

It gives me an error on some database servers
Line 3: Incorrect syntax near 'LOGIN'.

I tried this on the server it fails  and this works on some server
USE [master]
GO
if not exists(select * from syslogins where name = 'ABC\apps_dev')
begin
      exec sp_grantlogin 'ABC\apps_dev'
end
GO

I would like to know why these versions work on some servers, is this a versioning issue and how can I verify which version is used.

0
Comment
Question by:countrymeister
  • 3
5 Comments
 
LVL 37

Expert Comment

by:momi_sabag
Comment Utility
create login only works on sql 2005
won't work on sql 2000
0
 
LVL 1

Author Comment

by:countrymeister
Comment Utility
momi_sabaq

How can I verify the version of the database server
0
 
LVL 13

Expert Comment

by:devsolns
Comment Utility
You have to use the syntax below for SQL SERVER 2000:

EXEC sp_grantlogin 'Corporate\Test'
EXEC sp_addlogin 'test','hello'

See this link:
http://support.microsoft.com/kb/325003
0
 
LVL 13

Accepted Solution

by:
devsolns earned 250 total points
Comment Utility
To Get the version:
SELECT  SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
0
 
LVL 13

Expert Comment

by:devsolns
Comment Utility
See this link to match the product versions to what you have returned from the query above:

http://support.microsoft.com/kb/321185
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now