Creating Databse!

Hi All,

How to determine whether the MS SQL Server user has the premission to create database programmatically?

With Regards,
Who is Participating?
dds110Connect With a Mentor Commented:
example of creating a database with sql server and vb

checking the users permissions within sql server (article from

How do I get the current user’s effective permissions?

If you want to check whether the current user has a certain statement, object, or column permission, you can use the PERMISSIONS() function. The PERMISSIONS() function gives you the effective permissions that result from NT groups, server roles, and the user’s database role membership as well as explicit permissions granted to that user.

You can invoke the PERMISSIONS() function with no arguments to check statement permissions, with an object ID to check object permissions, or with both an object ID and a column name to check column permissions. The function returns an integer with a bitmap that contains the effective permissions. SQL Server Books Online (BOL) provides a detailed explanation about how to use this function and which bits represent which permissions. Listing 5 contains a few examples that demonstrate how to use the PERMISSIONS() function.


You can use the ListDatabasePermissions Method of the user object (all done through sql-dmo) to enumerate the users permissions.  See this link for more info (it's in C, but I think you can manage).
Error trapping!

You could attempt the create database functionality.  If it errs out, then he/she doesn't have the permission.  Otherwise, he/she does.  You'll need to determine the exact error number from SQL Server if you want to provide specific error handling.


Public Function CreateANewDB()
On Error GoTo err_create:
'code to create the new db

'clean up any used variables and close the function
Exit Function

MsgBox Err.Description,,Err.Number
Resume exit_create:
End Sub

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

callilamAuthor Commented:

I dont want to create a database. But, just want to know whether the user has the previledge to create the database.

Also, It is not possible to create database from VB.

With Thanks,
OK, so try to create the database anyway.  If it's created, great, the user has access to create databases.  Then delete the database.

In addition, it is too possible to create a database from vb.  However, at this time i'm not sitting in front of a computer with vb installed so I can't be of much help.  But I'll look around and see what I can find for ya.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.