473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Create User cmd problem

Hi,
I'm writing c# app and I want to add a new login and user to a SS 2005 DB using Stored Procedure.
I've come with the folowing code:

DECLARE @fullName nvarchar(50)
SET @fullName = @lastName+' '+@firstName

SET @cmd = 'CREATE USER '+ @fullName +' FOR LOGIN ' + @shortName;
EXEC sp_executesql @cmd
can someone tell me how can I create a new user with a space between first and a last name ?
Oct 26 '08 #1
3 2499
debasisdas
8,127 Expert 4TB
I am don't think spaces are allowed .

Try enclosing the fullname with double quotes. That might help.
Oct 26 '08 #2
I've already tried with the " but it did not work either :(

If it's no problem to create that kind of user, using wizard from the context menu on the DB>Security>Users>New user ... - there should be some way of doing the same thing from the code level
Oct 26 '08 #3
Ok I've did some research and came up with an answer to my problem:


Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE test
  2. AS
  3. DECLARE @s nvarchar(20)
  4. SET @s = 'jeden dwatrzy'
  5. EXEC sp_adduser test2 ,@s


or with the usage of the transaction
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE test
  2. AS
  3. BEGIN transaction
  4. DECLARE @s nvarchar(100)
  5. declare @a nvarchar(30)
  6. SET @a = '[jakis nowy]'
  7.  
  8. SET @s = 'CREATE USER'+ @a +' FOR LOGIN [test2]'
  9. EXEC sp_executesql @s
  10. COMMIT transaction
Oct 27 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: lkrubner | last post by:
I have a webserver through Rackspace. I create a domain. I create an FTP user. I upload some files. I create a database called testOfSetupScript and then I create a database user named setup. I...
0
by: Renato Neves | last post by:
The following code is working fine, i can create the user in the Active Directory and "enable" it. My problem is that, when i'm trying to authenticate him, i can't get to work!! The user and pass...
6
by: Chris Travers | last post by:
Hi all; I am using PostgreSQL 7.4 on RedHat 9, though I don't think that is important to this problem. I am attempting to write a rule that will check to see whether certain conditions are...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
2
by: Vincent Nguyen | last post by:
Hi, I have problem create exchange 2000 mailbox using CDOEXM in my Web Service application. The error I got was "Catastrophic failure". Here is the code that I have: DirectoryEntry user =...
4
by: I_AM_DON_AND_YOU? | last post by:
There is one more problem I am facing but didn't get the solution. In my Setup Program I am not been able to create 2 things (when the program is intalled on the client machine ) : (1) create...
6
by: Philip Wagenaar | last post by:
What is the best way to create a local user on the machine with administrator rights? I have problems with my code on machines that have password policy. The problem is that when the user is...
2
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
2
by: Jeff | last post by:
Hey ASP.NET 2.0 I'm developing a web portal where users must login to. As far as I know all users are accessible from the MembershipUserCollection. I know that current user is also accessible...
16
by: Mich | last post by:
Hi, i'm building an web application for anonymous users. They can take a look in the website, nothing more. In order to perform other actions, the anonymous user must be logged. So i create an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.