Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 8th, 2005, 02:09 PM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , .
Posts: 121
Thanks: 1
Thanked 0 Times in 0 Posts
Default Create SQL Server users programmatically?

Hello,
I have a question for everybody:
How to create SQL Server's database user programmatically and how to assign the role (or permission level) for new or an existing user?
Any code examples or referrals will be gladly appreciated.
Thanks in advance,
   -Dmitriy


Reply With Quote
  #2 (permalink)  
Old December 13th, 2005, 06:12 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

In the case of Oracle, there is a program for talking to the database textually called SQLPlus. Usin gthis program which looks much like NotePad, you can manipulate the database directly. You can retrieve information (records, table definitions, account stati, etc.).

You can also create users using language specific to Oracle.

If you create a connection to an Oracle DB in VB, you can do exactly the same thing by passing textual instructions over the connection, using a command object.

I’m quite sure the SQL Server is exactly the same.

It is important that the connection be made using the login of the person having the approriate authority level for what the actions will be, but I presume you will be able to do that.

Again, in Oracle, if you are going to make objects for the person to use (such as tables, stored procedures, etc), the connection will need to be established impersonating that user if they are to have authority over the objects. I presume it is similar in SQL Server.
Reply With Quote
  #3 (permalink)  
Old December 14th, 2005, 03:37 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Go into MS SQL Query Analyzer, log into your favorite MSSQL DB, then enter "sp_help" in the query window (with the default install of the analyzer you can also hit ALT-F1 as a shortcut). You'll see a list of all the objects in the database. When on the 'master' DB you'll see all the master objects such as stored procedures used for system administration tasks.

Among those sprocs are these two:
sp_addlogin
sp_adduser

Those look like they may be part of what you need. A little more exploring around the SP_HELP list should find you some more.

A couple more helpful hints on some built in sprocs:
'sp_help' will show you the schema details of an object. Example:
    sp_help MyTable
    sp_help MyStoredProcedure
'sp_helptext' will show the text of a stored procedure. Example:
    sp_helptext MyStoredProcedure
    sp_helptext sp_helptext

You can highlite a db object name (table, sproc) and hit ALT-F1 and it will display the object's schema. If you work with sprocs a lot, you can add a similar shortbut by going to Tools->Customize and adding "sp_helptext" to one of the empty shortcut keys. Then you can highlite a sproc name and just hit the shortcut key to see the text of the sproc.

-Peter
Reply With Quote
  #4 (permalink)  
Old December 15th, 2005, 04:29 PM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , .
Posts: 121
Thanks: 1
Thanked 0 Times in 0 Posts
Default


Thanks very much for your input

-Dmitriy

Reply With Quote
  #5 (permalink)  
Old October 29th, 2008, 03:14 PM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2007
Location: , VA, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

See http://www.experts-exchange.com/Prog..._22856885.html

Code:
CREATE LOGIN [DOMAIN\username] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english]
GO
EXEC sys.sp_addsrvrolemember @loginame = N' DOMAIN\username, @rolename = N'sysadmin'
EXEC sp_addrolemember 'db_owner', [DOMAIN\username]

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create SQL Server user programmatically? Dmitriy Pro VB Databases 1 March 8th, 2006 10:02 AM
Create SQL Server database user programmatically? Dmitriy VB.NET 3 January 3rd, 2006 12:30 PM
create SQL Server table from Access PorcupineRabbit SQL Server DTS 2 December 30th, 2005 06:11 AM
Create SQL Server database user programmatically? Dmitriy Pro VB 6 0 December 8th, 2005 02:04 PM



All times are GMT -4. The time now is 01:02 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.