LocalDB Using SQL Server Management Studio 2012 (SSMS)
Join the DZone community and get the full member experience.
Join For Freeok, in the previous post we determined how we could attach to localdb using ssms 2012. next stop, creating a database. turns out that it's potentially harder than it seems at first.
now that i've gotten connected, i went to try to create a database. right click on the connection, create new database. fill in the name, press ok.
boom. errors like the following:
title: microsoft sql server management studio ------------------------------ create failed for database 'test'. (microsoft.sqlserver.smo) for help, click: http://go.microsoft.com/fwlink?prodname=microsoft+sql+server&prodver=11.0.2100.60+((sql11_rtm).120210-1846+)&evtsrc=microsoft.sqlserver.management.smo.exceptiontemplates.failedoperationexceptiontext&evtid=create+database&linkid=20476 ------------------------------ additional information: an exception occurred while executing a transact-sql statement or batch. (microsoft.sqlserver.connectioninfo) ------------------------------ a file activation error occurred. the physical file name 'test.mdf' may be incorrect. 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) for help, click: http://go.microsoft.com/fwlink?prodname=microsoft%20sql%20server&prodver=11.00.2100&evtsrc=mssqlserver&evtid=5105&linkid=20476 ------------------------------ buttons: ok ------------------------------
... and digging into the details, looks like the following:
=================================== create failed for database 'test'. (microsoft.sqlserver.smo) ------------------------------ for help, click: http://go.microsoft.com/fwlink?prodname=microsoft+sql+server&prodver=11.0.2100.60+((sql11_rtm).120210-1846+)&evtsrc=microsoft.sqlserver.management.smo.exceptiontemplates.failedoperationexceptiontext&evtid=create+database&linkid=20476 ------------------------------ program location: at microsoft.sqlserver.management.smo.sqlsmoobject.createimpl() at microsoft.sqlserver.management.sqlmanagerui.createdatabasedata.databaseprototype.applychanges(control marshallingcontrol) at microsoft.sqlserver.management.sqlmanagerui.createdatabase.dopreprocessexecution(runtype runtype, executionmode& executionresult) at microsoft.sqlserver.management.sqlmgmt.sqlmgmttreeviewcontrol.dopreprocessexecutionandrunviews(runtype runtype) at microsoft.sqlserver.management.sqlmgmt.sqlmgmttreeviewcontrol.executeforsql(preprocessexecutioninfo executioninfo, executionmode& executionresult) at microsoft.sqlserver.management.sqlmgmt.sqlmgmttreeviewcontrol.microsoft.sqlserver.management.sqlmgmt.iexecutionawaresqlcontrolcollection.preprocessexecution(preprocessexecutioninfo executioninfo, executionmode& executionresult) at microsoft.sqlserver.management.sqlmgmt.viewswitchercontrolsmanager.runnow(runtype runtype, object sender) =================================== an exception occurred while executing a transact-sql statement or batch. (microsoft.sqlserver.connectioninfo) ------------------------------ program location: at microsoft.sqlserver.management.common.serverconnection.executenonquery(string sqlcommand, executiontypes executiontype) at microsoft.sqlserver.management.common.serverconnection.executenonquery(stringcollection sqlcommands, executiontypes executiontype) at microsoft.sqlserver.management.smo.executionmanager.executenonquery(stringcollection queries) at microsoft.sqlserver.management.smo.sqlsmoobject.executenonquery(stringcollection queries, boolean includedbcontext) at microsoft.sqlserver.management.smo.sqlsmoobject.createimplfinish(stringcollection createquery, scriptingpreferences sp) at microsoft.sqlserver.management.smo.sqlsmoobject.createimpl() =================================== a file activation error occurred. the physical file name 'test.mdf' may be incorrect. diagnose and correct additional errors, and retry the operation. create database failed. some file names listed could not be created. check related errors. (.net sqlclient data provider) ------------------------------ for help, click: http://go.microsoft.com/fwlink?prodname=microsoft%20sql%20server&prodver=11.00.2100&evtsrc=mssqlserver&evtid=5105&linkid=20476 ------------------------------ server name: (localdb)\v11.0 error number: 5105 severity: 16 state: 2 line number: 1 ------------------------------ program location: at microsoft.sqlserver.management.common.connectionmanager.executetsql(executetsqlaction action, object execobject, dataset filldataset, boolean catchexception) at microsoft.sqlserver.management.common.serverconnection.executenonquery(string sqlcommand, executiontypes exe
so what's going on here? i open up a query window, type the following and run it:
create database [test] go
that works fine? what gives?
rooting around the file system a bit gives the answer. when creating a database via ddl script, like this, the default output directory is "c:\users\adam" (yours will be your name, of course), and the database files end up in that directory. looking at my drive, i now see test.mdf and test_log.mdf in that directory. however, looking at where ssms wants to create them reveals the problem. in the database files section of the general page in the new database dialog, scroll over to the right and have a look at the path location. it's set to <default path> . now click on the dot-dot-dot (ellipsis) and take a look at what that default path is...
c:\users\adam\appdata\local\microsoft\microsoft sql server local db\instances\v11.0
that's not gonna work, and besides, i'd never find the mdf file again if i put it in there.
so, change that path to "c:\users\adam" in the create database dialog fixes the problem, or just use the "create database" ddl instead.
Published at DZone with permission of Adam Hoffman, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Logging Best Practices Revisited [Video]
-
Effortlessly Streamlining Test-Driven Development and CI Testing for Kafka Developers
-
A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage
-
Build a Simple Chat Server With gRPC in .Net Core
Comments