Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3405
  • Last Modified:

Create Login script to the server

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
countrymeister
Asked:
countrymeister
  • 3
1 Solution
 
momi_sabagCommented:
create login only works on sql 2005
won't work on sql 2000
0
 
countrymeisterAuthor Commented:
momi_sabaq

How can I verify the version of the database server
0
 
devsolnsCommented:
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
 
devsolnsCommented:
To Get the version:
SELECT  SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
0
 
devsolnsCommented:
See this link to match the product versions to what you have returned from the query above:

http://support.microsoft.com/kb/321185
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now