在驱动器c中创建数据库 [英] make database in drive c

查看:116
本文介绍了在驱动器c中创建数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

我想在路径c:programfiles\winreg中创建数据库。我使用此代码,但我有错误:



hi.
i want make database in path "c:programfiles\winreg" . i use this code but i have error:

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()







但在路径c:winreg 我没有错误。

我该怎么办?????




but in path "c:winreg" i have no error.
what should i do?????

推荐答案

不好主意。没有硬编码路径名可能有用的情况(除了一些初步实验)。



这些名称应始终根据用户输入在运行时计算,一些配置文件和/或环境,例如为每个用户帐户设置的特殊文件夹为所有用户。



你不能保证该目录你会硬编码存在。事实上,没有任何东西可以保证甚至驱动C:存在。另一个问题是许可。在基于NT的操作系统中,您需要为此类任意命名目录设置权限。不要在系统管理方面做一些改变,最好避免使用这些目录。



-SA
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

错误5是拒绝访问。



您正在尝试创建一个位于普通用户ReadOnly位置的文件。 Program Files下的所有文件夹和文件都是ReadOnly。您无法在该文件夹下创建数据库。



将数据库放在更合适的位置,例如CommonApplicationData [ ^ ]。
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[^].


这篇关于在驱动器c中创建数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆