How to Create a Database When User does not have Permission

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This question is related to SQL Server Express SP2.

When the four gig limit of an SQL Express database is approached it is
desired to have another database created at run time with no user interaction.
The problem is that the user running the application may not have
permissions to create a database.
Is there a way to create a database even when the user that is running the
application does not have permissions to do so?
Maybe this needs to be done as a service?
 
First, why is the database approaching the max size? Are you storing TEXT or
IMAGE or other BLOB types? It would be far easier to store the path to the
image and manage the files separately.
Next, if you install as a User Instance, the application runs as SA so it
can create another database--however, this approach is, IMHO challenged.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
 
Hi Bill,

The data being stored would be high volume in the form of blobs.
We do not want to save the values as files and then reference them.
 
You could use impersonation while creating a new database. After
creation of the database, you need to switch back to original user.

Here is the C# code for impersonation.

[DllImport("advapi32.dll")]
public static extern bool LogonUser(
string userName, string domain, string password, int logonType,
int logonProvider, out int token);

int token;
loggedOn =
LogonUser(ConfigurationManager.AppSettings["userName"],
ConfigurationManager.AppSettings["computerName"],
ConfigurationManager.AppSettings["password"],
3, 0, out token);

WindowsImpersonationContext impersonationContext=null;
IntPtr intPtrToken;
intPtrToken = new IntPtr(token);
impersonationContext = WindowsIdentity.Impersonate(intPtrToken);


You can use the following code to switch back the original user context
after creating the database.

impersonationContext.Undo();


Of course, you need to know the user name and password for a user with
privilege to create a database.

Charles Zhang
SpeedyDB Technologies (SpeedyDB ADO.NET Provider)
http://www.speedydb.com
 
Back
Top