Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
hi.
i want make database in path "c:programfiles\winreg" . i use this code but i have error:

VB
System.IO.Directory.CreateDirectory("C:\\Program Files\\WinReg;)

      Dim con As New SqlConnection("Server=.\SQLEXPRESS;Trusted_Connection=True;")
      Dim cmd As New SqlCommand("CREATE DATABASE [Student] ON  PRIMARY" +
    "( NAME = N'Student', FILENAME = N'C:\\Program Files\\WinReg\\Student' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )" +
    "LOG ON " +
    "( NAME = N'Student_log', FILENAME = N'C:\\Program Files\\WinReg\\Student1' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)" +
    "COLLATE Persian_100_CI_AS_KS_WS", con)

      con.Open()
      cmd.ExecuteNonQuery()
      con.Close()



but in path "c:winreg" i have no error.
what should i do?????
Posted
Comments
[no name] 27-Sep-14 7:22am    
And what the error is?
N.B: Since about xp c:\program files\.... should not be used to save app data
Mohammad Hasanpoor 27-Sep-14 7:25am    
CREATE FILE encountered operating system error 5(failed to retrieve text for this error. Reason: 15105) while attempting to open or create the physical file 'C:\\Program Files\\WinReg\\Program\\DbSt\\Student'.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
[no name] 27-Sep-14 7:28am    
Yes, because apps should not save data in c:\program files\....
The dirty way is to give access rights for 'C:\\Program Files\\WinReg' (and Sub Folders) to whom it Needs.

The clean way is to use appdata folders
Mohammad Hasanpoor 27-Sep-14 7:29am    
and now what is answer? how can i do this?
[no name] 27-Sep-14 7:31am    
the dirty or the clean way?

Bad idea. There are no cases when a hard-coded path name can be useful (except maybe some preliminary experiments).

Such names should always be calculated during runtime based on user input, some configuration files and/or environment, such as "special folders" set up per each user account of for "all users".

You cannot guarantee that the directory you hard-coded will exist. In fact, nothing can guarantee you that even drive "C:" exists. Another problem is permission. In NT-based OS, you will need permission set up for such arbitrary named directory. Instead of doing some changes in system administration, it's always the best to avoid such directories.

—SA
 
Share this answer
 
Error 5 is "Access Denied".

You're trying to create a file that in a location that is "ReadOnly" to normal users. All folders and files under Program Files are ReadOnly. You can't create your database under that folder.

Put your database in a more appropriate location, such as in a folder under CommonApplicationData[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900