Creating Databse!

Posted on 2004-04-14
Last Modified: 2010-05-02
Hi All,

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

With Regards,
Question by:callilam
  • 5

Expert Comment

ID: 10824312
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


Expert Comment

ID: 10877402

Author Comment

ID: 10877698

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,
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.


Expert Comment

ID: 10997862
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.

Accepted Solution

dds110 earned 100 total points
ID: 10998038
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).

Expert Comment

ID: 11014808

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to create a duplicate finder Application 9 121
Using "ScreenUpdating" 6 63
VBA filters 2 60
Looking for VB6 code to read SQL table export it to ascii 8 38
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question