RE: Createing a DB with osql - passing in the DB name and user rig

Tech-Archive recommends: Speed Up your PC by fixing your registry



You guys are on a roll tonight - perfect - thanks

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




"Peter Yang [MSFT]" wrote:

Hello Dave,

I understand that you'd like to create database dynamically by using the
name the user inputs. Also, you'd like to select the user owns the created
database.

As far as I know, you could not pass a parameter to "create database"
statment as the database name. However, you could construct a string so
that you could execute the string directly.

declare @db varchar(50)
select @db='testdb'
select @db='create database ' +@db
Execute (@db)

You could run "select * from master..syslogins" to get all logins including
SQL and domain users and you way want to filter ntgroup by using isntgroup
column. You may want to use sp_changedbowner after creating the database.

Also, you could use SMO (2005) or DMO (2000) to create database
dynamically. Please refer to the following articles for details:

Database Class
http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.
database.aspx

How to: Create, Alter, and Remove a Database in Visual Basic .NET
http://msdn2.microsoft.com/en-us/library/ms162576.aspx

Create database in sql server using asp.net with C#
http://www.codeproject.com/useritems/Create_Database.asp

As for database owner, you could use SetOwener method in SMO to set owner
of the database. Also, you could enumerate logins in server object to get
all logins on the server:

Database.SetOwner Method
http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.
database.setowner.aspx

Server.Logins Property
http://msdn2.microsoft.com/en-gb/library/microsoft.sqlserver.management.smo.
server.logins.aspx

Logins Collection
http://msdn.microsoft.com/library/en-us/sqldmo/dmoref_c_l_4z72.asp?frame=tru
e

In DMO there is no method to set owner when creating database. However, you
could run sp_changedbowner after you create the database.

If you have any further concerns or comments, please feel free to let's
know. Thank you.

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications
<http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx>.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
<http://msdn.microsoft.com/subscriptions/support/default.aspx>.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


.



Relevant Pages

  • Re: What so special about PostgreSQL and other RDBMS?
    ... That's exactly the link the licence agreement for the database points to when it ... comes to what wecan expect for paying support. ... > "Oracle may provide additional releases or versions of its programs ... If the requirements are volatile I'd do a long term contract detailing what ...
    (comp.lang.php)
  • RE: GridView RowEditing Requery question
    ... Gridview is always retrieved from database directly? ... the calling side always get the cached resultset. ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)
  • Re: GridView RowEditing Requery question
    ... Gridview is always retrieved from database directly? ... ** Implement local cache in your ASP.NET application(for the data access ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)
  • Re: query-based update failed
    ... Could you please clarify a bit more on what you mean by "checking each record in your recordset to see if it is in your database table at that time"? ... Look forward to your response. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.sqlserver.odbc)
  • Re: VS2008 DBE (GDR)
    ... target database, which already has data in some lookup tables. ... Microsoft Online Community Support ... nature are best handled working with a dedicated Microsoft Support Engineer ...
    (microsoft.public.vsnet.general)