|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Createing a DB with osql - passing in the DB name and user rightsI have a .sql file that creates a database fine. I have two questions on this: 1) Is there a way to set the name of the database I am going to create dynamically? This will ship with our install program and it the installer will prompt the user for the name they want for the database and then create it. 2) How do I set which user owns the created database? And this needs to work for both a sqlserver or domain user. I don't want to create a user, just let the person installing select the user. And if possible, I would like to be able to give them a list of sqlserver users (domain users I know how to enumerate). -- thanks - dave david_at_windward_dot_net http://www.windwardreports.com Cubicle Wars - http://www.windwardreports.com/film.htm 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. You guys are on a roll tonight - perfect - thanks
-- Show quotethanks - 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. > > |
|||||||||||||||||||||||