Click here to Skip to main content
15,888,237 members
Home / Discussions / Database
   

Database

 
AnswerRe: it is wrong with this Pin
i.j.russell9-Oct-09 9:33
i.j.russell9-Oct-09 9:33 
GeneralRe: it is wrong with this Pin
Mohamed El-Wehishy9-Oct-09 9:38
Mohamed El-Wehishy9-Oct-09 9:38 
GeneralRe: it is wrong with this Pin
Luc Pattyn9-Oct-09 10:06
sitebuilderLuc Pattyn9-Oct-09 10:06 
GeneralRe: it is wrong with this Pin
Mohamed El-Wehishy9-Oct-09 10:16
Mohamed El-Wehishy9-Oct-09 10:16 
GeneralRe: it is wrong with this Pin
Luc Pattyn9-Oct-09 10:19
sitebuilderLuc Pattyn9-Oct-09 10:19 
GeneralRe: it is wrong with this Pin
εїзεїзεїз10-Oct-09 9:46
εїзεїзεїз10-Oct-09 9:46 
GeneralRe: it is wrong with this Pin
Not Active10-Oct-09 10:34
mentorNot Active10-Oct-09 10:34 
QuestionMSSQL Server 2005- Problem in creating strored procedure. Pin
priyamtheone9-Oct-09 2:52
priyamtheone9-Oct-09 2:52 
I'm trying to create a stored procedure in MSSQL Server 2005 that'll perform the following jobs:
1) Create a login.
2) Create an user in TestDB database for the login created in step 1.
3) Assign the role 'db_generaluser' to the user created in step 2.

The login name and password for the login to be created will be supplied from externally through input parameters. If this procedure executes successfully it returns 0 else 1 to the caller through an output parameter.

When I try to compile it, it's prompting the following error messages:
Msg 102, Level 15, State 1, Procedure sp_CreateLogin, Line 23
Incorrect syntax near '@loginname'.

Msg 319, Level 15, State 1, Procedure sp_CreateLogin, Line 23
Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.

Msg 319, Level 15, State 1, Procedure sp_CreateLogin, Line 27
Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.

What's my mistake? Plz help. My code follows:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- ==========================================================================================================
-- Author:	Priyamtheone
-- Create date: 2009-Oct-08
-- Description:	This procedure is used to create a login, create an user in TestDB database associated to
--		that login and assign the role 'db_generaluser' to that user. The login name and password
--		will be supplied from externally through input parameters. If this procedure executes
--		successfully it returns 0 else 1 to the caller through an output parameter.
-- ==========================================================================================================
CREATE PROCEDURE [dbo].[sp_CreateLogin] 
	-- Add the parameters for the stored procedure here.
	@loginname sysname,
	@passwd	sysname,
	@intRetVal int = 0 output	--Output parameter.
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT statements.
	SET NOCOUNT ON;
	SET @intRetVal = 0;

	BEGIN TRY
		CREATE LOGIN @loginname WITH PASSWORD=@passwd, DEFAULT_DATABASE=[TestDB], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF

		CREATE USER @loginname FOR LOGIN @loginname WITH DEFAULT_SCHEMA=[dbo]

		EXEC sp_addrolemember N'db_generaluser', @loginname
	END TRY
	BEGIN CATCH
		SET @intRetVal = 1;	--Something went wrong. So set the return value to 1.
	END CATCH
END
GO


modified on Friday, October 9, 2009 9:02 AM

Questionlooking for converting tool from one database to another Pin
E_Gold8-Oct-09 23:59
E_Gold8-Oct-09 23:59 
AnswerRe: looking for converting tool from one database to another Pin
Not Active9-Oct-09 1:20
mentorNot Active9-Oct-09 1:20 
AnswerRe: looking for converting tool from one database to another Pin
David Skelly9-Oct-09 2:39
David Skelly9-Oct-09 2:39 
Questionsense these changes immediately and notify my program Pin
reza assar8-Oct-09 23:44
reza assar8-Oct-09 23:44 
AnswerRe: sense these changes immediately and notify my program Pin
εїзεїзεїз9-Oct-09 4:39
εїзεїзεїз9-Oct-09 4:39 
QuestionRe: sense these changes immediately and notify my program Pin
reza assar11-Oct-09 17:05
reza assar11-Oct-09 17:05 
AnswerRe: sense these changes immediately and notify my program Pin
Ashfield12-Oct-09 3:49
Ashfield12-Oct-09 3:49 
QuestionDataGridView Access Problem [modified] Pin
Grollub8-Oct-09 9:11
Grollub8-Oct-09 9:11 
AnswerRe: DataGridView Access Problem Pin
Mycroft Holmes8-Oct-09 20:00
professionalMycroft Holmes8-Oct-09 20:00 
GeneralRe: DataGridView Access Problem Pin
Grollub9-Oct-09 4:05
Grollub9-Oct-09 4:05 
GeneralRe: DataGridView Access Problem Pin
Mycroft Holmes9-Oct-09 11:45
professionalMycroft Holmes9-Oct-09 11:45 
Questionstandard SqlServer 2008 Pin
ali_reza_zareian8-Oct-09 8:43
ali_reza_zareian8-Oct-09 8:43 
AnswerRe: standard SqlServer 2008 Pin
Mycroft Holmes8-Oct-09 20:03
professionalMycroft Holmes8-Oct-09 20:03 
AnswerRe: standard SqlServer 2008 Pin
εїзεїзεїз10-Oct-09 1:01
εїзεїзεїз10-Oct-09 1:01 
QuestionProblem in Query Pin
nagendrathecoder7-Oct-09 21:30
nagendrathecoder7-Oct-09 21:30 
AnswerRe: Problem in Query Pin
εїзεїзεїз7-Oct-09 21:58
εїзεїзεїз7-Oct-09 21:58 
AnswerRe: Problem in Query Pin
Mycroft Holmes7-Oct-09 22:26
professionalMycroft Holmes7-Oct-09 22:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.