Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 12th, 2014, 05:02 PM
Authorized User
 
Join Date: Jan 2009
Posts: 32
Thanks: 4
Thanked 0 Times in 0 Posts
Default Connecting to Database

I'm working on Chapter 13 trying to connect to the database that was created in Chapter 12. I see the database in the Solution Explorer and I double click on the database file as instructed in Step #6 on page 444. The Server Explorer opens and the database is listed under "Data Connections" but the icon has a red "X" over it. When I hit the refresh button, I get an error message as follows:

"Unable to open the physical file "C:\Planet_Wrox\App_Data\PlanetWrox.mdf". Operating system error 5: "5(Access is denied.)".
An attempt to attach an auto-named database for file C:\Planet_Wrox\App_Data\PlanetWrox.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."


I suspect it has something to do with Administrator permissions or something along those lines, but I'm not sure how to clear this up.

Might also be the "connectionstring" DataSource address in the webconfig file.

Thanks for any help you might be able to give.

Last edited by Psyclist; April 12th, 2014 at 05:34 PM..
 
Old April 13th, 2014, 04:14 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

A couple of things to check / questions:

1. Which version of SQL Server are you targeting? Express, or Local DB? And are you using Visual Studio 2013?

2. What are the permissions for the folder C:\Planet_Wrox\App_Data\ on disk? You can open the Properties of the folder in Windows and then look under the Security tab.

3. When you log in to SQL Server using Management Studio, do you see your database attached there already?

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 13th, 2014, 12:29 PM
Authorized User
 
Join Date: Jan 2009
Posts: 32
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Hi Imar,

The only option I get is SQLExpress. I don't get the option the Local DB option. It's SQL Server 2012 which is the version the book says to download.

As for permissions in question #2, "SYSTEM" is listed along with myself (my login name for windows), and Administrator (I'm the only user of this laptop, so I assume I'm logging in as the Admin).

#3: I uninstalled and reinstalled SQL Server, so at present, no I don't see it there. On the previous installation, I created the database/tables as instructed in chapter 12 and had no problem with that.

Thank you.
 
Old April 13th, 2014, 02:26 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Which version of Visual Studio are you using? LocalDB should be installed automatically with VS 2013.

That said, try running VS as an Administrator (right-click it on the Start Menu and choose Run as Administrator). Does that make a difference?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 13th, 2014, 02:48 PM
Authorized User
 
Join Date: Jan 2009
Posts: 32
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Ooops, sorry. Misread that.

I'm using "Visual Studio Express for the Web 2013."
 
Old April 13th, 2014, 02:51 PM
Authorized User
 
Join Date: Jan 2009
Posts: 32
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Get the same thing when I start it as Administrator.
 
Old April 13th, 2014, 02:52 PM
Authorized User
 
Join Date: Jan 2009
Posts: 32
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Actually, now I don't see the database in the Server Explorer. I just see the connection string name (PlanetWroxConnectionString1). It has the red "X". I don't see LocalDB under "Servers" either.

Last edited by Psyclist; April 13th, 2014 at 03:00 PM..
 
Old April 13th, 2014, 03:32 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

A few things to check:

1. What happens when you double-click the MDF in the App_Data folder.

2. What do you have under Tools | Options | Database Tools | Data Connections | SQL Server Instance in Visual Studio?

3. When you use SQL Server Management Studio, what happens wen you try to connect to the server name (LocalDB)\v11.0 ?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 13th, 2014, 03:56 PM
Authorized User
 
Join Date: Jan 2009
Posts: 32
Thanks: 4
Thanked 0 Times in 0 Posts
Default

When I double-click on the database file in the Solution Explorer, I get a dialog box with the following content:

"Unable to open physical file "C:\Planet_Wrox\App_Data\PlanetWrox.mdf". Operating system Error 5: "5(Access is denied.)". An attempt to attach an auto-named database for file C:\Planet_Wrox\App_Data\PlanetWrox.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."

I click on the OK button to dismiss this dialog box and Server Explorer shows "PlanetWroxConnectionString1" under "Data Connections", and "laptop" under "Servers".

Question #2: (LocalDB)\v11.0 is in the box below "SQL Server Instance Name".

Question #3: When I open SQL Server Management Studio, a dialog box opens - "Connect to Server". In the "Server Name" dropdown it defaults to LAPTOP/SQLEXPRESS. When I click on the arrow to dropdown options, the only other item in the list is <browse for more...>. When I click on that a dialog box opens with two tabs, one labeled, "Local Servers" which has "Database Engine" with a + sign to the left of it. When I click on the + sign, only LAPTOP\SQLEXPRESS displays. The other tab is "Network Servers" and has "Database Engine" in it with a + sign to the left. When I click on the +, only LAPTOP displays.

I connect to LAPTOP\SQLEXPRESS and in the "Object Explorer" window, it says "LAPTOP\SQLEXPRESS(SQL Server 11.0.2100 - laptop\MyName)

Last edited by Psyclist; April 13th, 2014 at 04:07 PM..
 
Old April 13th, 2014, 05:04 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

For item 3, try entering the name I suggested in the Server name box manually

Code:
 (LocalDB)\v11.0
Does that give you access to Local DB?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting to Database bryantms ASP.NET 3.5 Basics 3 July 9th, 2008 12:34 AM
connecting to database stealthdevil Visual Basic 2005 Basics 2 November 5th, 2007 01:31 PM
Connecting to a database mfos Classic ASP Basics 0 December 20th, 2006 07:59 AM
connecting to a database nehalw VB.NET 0 January 5th, 2005 05:59 AM
database connecting princeofdhump Classic ASP Databases 3 August 7th, 2004 02:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.