1

I can try to publishing my application but I have 2 problems: my first is I can't create database with this code

if not exists(select * from sys.databases where name = 'deneme1db') 
begin 
    CREATE DATABASE deneme1db ON PRIMARY 
    (NAME = deneme1db,FILENAME = 'C:\\deneme1db.mdf',
     SIZE = 5MB, MAXSIZE = 10MB, FILEGROWTH = 10%) 
     LOG ON (NAME = deneme1db_log, FILENAME = 'C:\\deneme1db_log.ldf',
     SIZE = 1MB, MAXSIZE = 10MB, FILEGROWTH = 10%) 
 end

I get this error

Msg 5123, Level 16, State 1, Line 1
CREATE FILE encountered operating system error 5(Access Denied.) while attempting to open or create the physical file 'C:\deneme1db.mdf'.

Msg 1802, Level 16, State 4, Line 1
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

My second error on registry. I try the run this

string[] sql = (string[])Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Microsoft")
       .OpenSubKey("Microsoft SQL Server").GetValue("InstalledInstances");
 var ar = (from s in sql where s.Contains("SQLEXPRESS") select s ).FirstOrDefault();
 if(ar==null)
 {
     label1.Text = "no value";
 }
 else
 {
     label1.Text = "find value";
 }

string[] sql every time returns null but if I change the prefer-32 bit from build properties code run but can't change on setup

kerem ayseli
  • 41
  • 1
  • 5
  • 2
    The first error is most likely because whatever account the sql server instance is running against doesn't have access to the root of c: – MikeS Jan 07 '19 at 14:45
  • 1
    These appear to be two unrelated questions. You'll get a better response if you post them as separate questions, including only the details relevant to each question. – Diado Jan 07 '19 at 14:46
  • Thanks for information ı can solved first problem just change the location 'C:\\\deneme1db.mdf – kerem ayseli Jan 07 '19 at 18:28

1 Answers1

0

ı can solved my first problem just change the database location

FILENAME = 'C:\select your database location\deneme1db.mdf 

For second problem

OpenSubKey() returns null for a registry key that I can see in regedit.exe

kerem ayseli
  • 41
  • 1
  • 5