Operating system error 5(access is denied) when creating Database at Client Machine in C:\ Drive

StackOverflow https://stackoverflow.com/questions/12193176

Frage

I am installing SQL Server Express 2005 as a prerequisite of my c# windows form application, and under the Custom Action of my installer class, I'm trying to execute the script below, to create my database on the user machine.

However when I choose to create the database on the C:\ drive(the windows root folder), I am getting this error/exception:

Operating system error 5(access is denied)

I do not get any error if I try to do so in any other drive.

Please Help me. How can I get the relevant privileges for this SQL query?

USE [master]
GO
/****** Object:  Database [Society_security_database]    Script Date: 08/11/2012 14:26:23 ******/
CREATE DATABASE [Society_security_database] ON  PRIMARY 
( NAME = N'Society_security_database', FILENAME = N'C:\Society_security_database.mdf' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'Society_security_database_log', FILENAME = N'C:\Society_security_database.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
 COLLATE SQL_Latin1_General_CP1_CI_AS
GO
EXEC dbo.sp_dbcmptlevel @dbname=N'Society_security_database', @new_cmptlevel=90
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [Society_security_database].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [Society_security_database] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [Society_security_database] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [Society_security_database] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [Society_security_database] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [Society_security_database] SET ARITHABORT OFF 
GO
ALTER DATABASE [Society_security_database] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [Society_security_database] SET AUTO_CREATE_STATISTICS ON 
GO
ALTER DATABASE [Society_security_database] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [Society_security_database] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [Society_security_database] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [Society_security_database] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [Society_security_database] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [Society_security_database] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [Society_security_database] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [Society_security_database] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [Society_security_database] SET  ENABLE_BROKER 
GO
ALTER DATABASE [Society_security_database] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [Society_security_database] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [Society_security_database] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [Society_security_database] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [Society_security_database] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [Society_security_database] SET  READ_WRITE 
GO
ALTER DATABASE [Society_security_database] SET RECOVERY SIMPLE 
GO
ALTER DATABASE [Society_security_database] SET  MULTI_USER 
GO
ALTER DATABASE [Society_security_database] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [Society_security_database] SET DB_CHAINING OFF 
War es hilfreich?

Lösung

Finally reached to the solution Because i was trying to access from a database as from Network Service account . when i changed that to local system it worked ! Here is the code

Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer mc = new Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer();
                Microsoft.SqlServer.Management.Smo.Wmi.Service svc = mc.Services["MSSQL$SQLEXPRESS"];
                svc.SetServiceAccount("LocalSystem",null);
                svc.Alter();
                SqlConnection.ClearAllPools();

It changes the service account to localSystem

Andere Tipps

I came the similar problem. After hell lot of analysis, I figured a simple fix for my issue. Close your Visual Studio. Open it again as Administrator and this should work.

Hope it helps.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top