简体   繁体   English

无法在 SQL Server 2012 中创建数据库

[英]Can't create a database in SQL Server 2012

I have recently installed SQL Server 2012 on my machine.我最近在我的机器上安装了 SQL Server 2012。 When I try to create a database in SSMS by right clicking on Databases and selecting New Database , it prompts me for various items in order to create the database.当我尝试通过右键单击Databases并选择New Database在 SSMS 中创建New Database ,它会提示我输入各种项目以创建数据库。 After entering the name of the database and clicking OK, I get an exception:输入数据库名称并单击“确定”后,出现异常:

"Create failed for Database 'aaaa'. (Microsoft.SqlServer.Smo) “为数据库‘aaaa’创建失败。(Microsoft.SqlServer.Smo)

ADDITIONAL INFORMATION:附加信息:

An exception occurred while executing a Transact-SQL statement or batch.执行 Transact-SQL 语句或批处理时发生异常。 (Microsoft.SqlServer.ConnectionInfo) (Microsoft.SqlServer.ConnectionInfo)

A file activation error occurred.发生文件激活错误。 The physical file name 'aaaa.mdf' may be incorrect.物理文件名“aaaa.mdf”可能不正确。 Diagnose and correct additional errors, and retry the operation.诊断并更正其他错误,然后重试该操作。 CREATE DATABASE failed.创建数据库失败。 Some file names listed could not be created.无法创建列出的某些文件名。 Check related errors.检查相关错误。 (Microsoft SQL Server, Error: 5105)" (Microsoft SQL Server,错误:5105)”

It seems the problem is only with the wizard because when I execute Create Database query it successfully creates the database.似乎问题仅出在向导上,因为当我执行Create Database查询时,它成功地创建了数据库。

I figured it out that when Database is created from wizard, a file path is to be provided in Path column.我发现当从向导创建数据库时,将在路径列中提供文件路径。 If it is blank by default then it means there is no path specified in Database settings.如果默认为空,则表示数据库设置中没有指定路径。

In Object Explorer, right-click a server and click Properties.在对象资源管理器中,右键单击服务器并单击属性。 In the left panel, click the Database settings page.在左侧面板中,单击数据库设置页面。 In Database default locations, view the current default locations for new data files and new log files.在数据库默认位置中,查看新数据文件和新日志文件的当前默认位置。 To change a default location, enter a new default path name in the Data or Log field, or click the browse button to find and select a path name .要更改默认位置,请在数据或日志字段中输入新的默认路径名称,或单击浏览按钮查找并选择路径名称

We can change the file path while creating Database.我们可以在创建数据库时更改文件路径。

实际数据库文件权限设置为只读,请尝试取消选中文件权限上的只读复选框。

I also had this problem and I can in this link where I've created any string values (DefaultData and DefaultLog) in regedit in this path: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSSQLServer\\MSSQLServer.我也遇到了这个问题,我可以在这个链接中在这个路径中的 regedit 中创建任何字符串值(DefaultData 和 DefaultLog):HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSSQLServer\\MSSQLServer。 In this "string values" you must put the path where your SQL data and log must stay.在此“字符串值”中,您必须放置 SQL 数据和日志必须保留的路径。

As you realized there is a Path column in the grid view for each file ( .mdf and .ldf ).正如您所意识到的,每个文件( .mdf.ldf )的网格视图中都有一个Path列。

This is set to <default> .这被设置为<default>

At the first usage of the server this default path may not be set, so the full-path of the new database cannot be computed.首次使用服务器时,可能未设置此默认路径,因此无法计算新数据库的完整路径。

Solution:解决方案:

Based on this article you can set it via the interface of SSMS.基于本文,您可以通过SSMS的界面进行设置。 You just need to:你只需要:

  1. right click on your server name (eg: (LocalDB)\\v11.0 ),右键单击您的服务器名称(例如: (LocalDB)\\v11.0 ),
  2. select Properties ,选择属性
  3. select Database Settings ,选择数据库设置
  4. Fill up all 3 entry of Database default locations with valid directory paths.用有效的目录路径填写数据库默认位置的所有 3 个条目。 (Defining top 2 paths: Data and Log is enough to create databases.) (定义前 2 条路径:数据日志足以创建数据库。)

This will create the right registry entries for you, without touching regedit.exe.这将为您创建正确的注册表项,而无需触及 regedit.exe。

What path to choose?选择什么路径?

Either the location that is proposed along installation:沿安装建议的位置:

C:\\Program Files\\Microsoft SQL Server\\MSSQL11.MSSQLSERVER\\MSSQL\\Data


Or the location of system databases :系统数据库的位置:

C:\\Users\\[UserName]\\AppData\\Local\\Microsoft\\Microsoft SQL Server Local DB\\Instances\\v11.0


Or better choices for non-system databases are:或者非系统数据库的更好选择是:

C:\\Users\\[UserName]\\My Documents\\Databases

C:\\Users\\[UserName]\\My Documents\\SQL Server Management Studio\\Databases

Note 1: [UserName] can be " Public " to make it common data (please correct me if this causes multiple copy of the database, but I think it won't).注 1: [UserName]可以是“ Public ”以使其成为公共数据(如果这会导致数据库的多个副本,请纠正我,但我认为不会)。

Note 2: I don't know whether latter is deleted along uninstallation of SSMS.注2:不知道卸载SSMS后是否删除了后者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CREATE DATABASE权限在数据库“ master”中被拒绝。 SQL Server 2012 - CREATE DATABASE permission denied in database 'master'. SQL Server 2012 我无法从Visual Studio 2012连接到我的SQL Server 2014数据库 - I can't connect to my SQL Server 2014 database from Visual Studio 2012 无法从Visual Studio Express 2012创建SQL Server数据库 - Unable to create SQL Server database from Visual Studio Express 2012 如何使用C#创建SQL Server 2012数据库? - How to create SQL Server 2012 database with C#? 如果未安装SQL Server 2005,是否可以创建并连接到SQL Server CE数据库? - Can I create and connect to a SQL Server CE database if SQL Server 2005 isn't installed? 无法连接到Visual Studio 2012中的SQL Server - Can't connect to SQL Server in visual studio 2012 在VS2012中无法使用SQL Server CE - Can't use SQL Server CE in VS2012 无法连接到 SQL Server Express 2012 / 2016 上的本地主机 - Can't connect to localhost on SQL Server Express 2012 / 2016 如何恢复 SQL Server 2012 数据库? - How to restore SQL Server 2012 database? 如何使用InstallShield LE为带有SQL Server 2012本地数据库的Visual Studio 2012 Windows窗体应用程序创建setup.exe文件 - How to create a setup.exe file using InstallShield LE for a Visual Studio 2012 Windows Forms Application with SQL Server 2012 Local Database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM