Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > BOOK: Beginning ASP.NET 4.5 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 18th, 2013, 02:23 PM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default It is not liking the connection string.

One important thing is that it is not liking the connection to the database. You can pull up the page to Planet Wrox by going to http://localhost just fine but when you try to pull up the parts of the website that require data connectivity you get an error message and are unable to connect. It has to be some kind of stupid permissions issue, with SQL Server or something else that I can't quite figure out. I did everything else to the letter in the instructions on the book and it can't make the connection to the database for some crazy reason.

Here are the corrected connection strings:

<add name="PlanetWroxConnectionString1" connectionString="Data Source=.\SqlExpress;AttachDbFilename=|DataDirector y|\PlanetWrox.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
<add name="PlanetWroxEntities" connectionString="metadata=res://*/App_Code.PlanetWrox.csdl|res://*/App_Code.PlanetWrox.ssdl|res://*/App_Code.PlanetWrox.msl;provider=System.Data.SqlCl ient;provider connection string=&quot;data source=.\SqlExpress;attachdbfilename=|DataDirector y|\PlanetWrox.mdf;integrated security=True;User Instance=True;MultipleActiveResultSets=True;App=En tityFramework&quot;" providerName="System.Data.EntityClient"/>

Here is the error message:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
)

Last edited by vbboyd; May 18th, 2013 at 02:49 PM..
Reply With Quote
  #2 (permalink)  
Old May 19th, 2013, 05:23 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Can you provide more context? What are you trying to accomplish? Are you deploying your site under IIS or does this happen in VS? Also, is the error message correct? Do you have an instance of SQL Server called .\SqlExpress?

I need lot more information in order to help you out.

When you post code, please copy it to Notepad first and then wrap it in code tags here using the # button. Otherwise, this forum messes up the code which may introduce errors that don't exist (note the spaces in your connection strings above) or hide the real problem. Can you repost the code just to make sure they are fine?

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!

Last edited by Imar; May 19th, 2013 at 11:04 AM..
Reply With Quote
  #3 (permalink)  
Old May 19th, 2013, 09:02 AM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default More context to the problem

I was on page 756, step 9 and that is what happened when I got to that step. I have the version of SQL Server that was installed when I loaded the commercial version of Visual Studio 2012. I assumed that SQL Express was loaded as a default when you installed the commercial version of 2012.
I didn't know that I had posted code. I thought that connection strings were an XML thing not ASP.NET C# code. But if you like I can re-post the connection strings from that VS project again so you can see.
Code:
<add name="PlanetWroxConnectionString1" connectionString="Data Source=.\SqlExpress;AttachDbFilename=|DataDirectory|\PlanetWrox.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
    <add name="PlanetWroxEntities" connectionString="metadata=res://*/App_Code.PlanetWrox.csdl|res://*/App_Code.PlanetWrox.ssdl|res://*/App_Code.PlanetWrox.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SqlExpress;attachdbfilename=|DataDirectory|\PlanetWrox.mdf;integrated security=True;User Instance=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient"/>
I am sorry I gave you the wrong error message I accidentally posted the wrong error message in the previous post. My bad. Here is the proper error message.:
Code:
Unable to open the physical file "C:\BegASPNET\Release\App_Data\PlanetWrox.mdf". Operating system error 5: "5(Access is denied.)".
An attempt to attach an auto-named database for file C:\BegASPNET\Release\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.

Last edited by vbboyd; May 19th, 2013 at 09:26 AM..
Reply With Quote
  #4 (permalink)  
Old May 19th, 2013, 11:03 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
I didn't know that I had posted code. I thought that connection strings were an XML thing not ASP.NET C# code.
I didn't mention C# code, just code, referring to the connection strings.

Quote:
Unable to open the physical file "C:\BegASPNET\Release\App_Data\PlanetWrox.mdf" . Operating system error 5: "5(Access is denied.)".
This implies a security issue. For which account did you configure permissions as described in step 7 of that same page?

Also, try removing "User instance=true" from the connection string.

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!
Reply With Quote
  #5 (permalink)  
Old May 19th, 2013, 11:48 AM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default Did all of that and I got the same problems

Just so you know I just opened up SQL Server Management studio and I have six attachments to the PlanetWrox database for chapters 14, 15,16,17 and 18. I don't know if that means anything or not.

I gave user .NET v4.5 full control of the AppData folder in windows explorer and I took out the user Instance = true part of the code and I still got the same problem.

Here is the error message stack trace for everything:

Code:
Server Error in '/' Application.

CREATE DATABASE permission denied in database 'master'.
An attempt to attach an auto-named database for file C:\BegASPNET\Release\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.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: CREATE DATABASE permission denied in database 'master'.
An attempt to attach an auto-named database for file C:\BegASPNET\Release\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.

Source Error: 


Line 18:                               select review;
Line 19:       Repeater1.DataSource = authorizedReviews;
Line 20:       Repeater1.DataBind();
Line 21:     }
Line 22:   }

Source File: c:\BegASPNET\Release\Reviews\All.aspx.cs    Line: 20 

Stack Trace: 


[SqlException (0x80131904): CREATE DATABASE permission denied in database 'master'.
An attempt to attach an auto-named database for file C:\BegASPNET\Release\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.]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5296071
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +558
   System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1682
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +69
   System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +30
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +317
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +889
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +307
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) +434
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +225
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +37
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions) +558
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions) +67
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1052
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +167
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +143
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +83
   System.Data.SqlClient.SqlConnection.Open() +96
   System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +44

[EntityException: The underlying provider failed on Open.]
   System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +203
   System.Data.EntityClient.EntityConnection.Open() +104
   System.Data.Objects.ObjectContext.EnsureConnection() +75
   System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +41
   System.Data.Objects.ObjectQuery`1.GetIListSourceListInternal() +13
   System.Data.Objects.ObjectQuery.System.ComponentModel.IListSource.GetList() +10
   System.Web.UI.DataSourceHelper.GetResolvedDataSource(Object dataSource, String dataMember) +57
   System.Web.UI.WebControls.ReadOnlyDataSource.System.Web.UI.IDataSource.GetView(String viewName) +42
   System.Web.UI.WebControls.Repeater.ConnectToDataSourceView() +60
   System.Web.UI.WebControls.Repeater.GetData() +13
   System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +89
   System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +61
   System.Web.UI.WebControls.Repeater.DataBind() +105
   Reviews_All.Page_Load(Object sender, EventArgs e) in c:\BegASPNET\Release\Reviews\All.aspx.cs:20
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Last edited by vbboyd; May 19th, 2013 at 11:57 AM..
Reply With Quote
  #6 (permalink)  
Old May 19th, 2013, 11:57 AM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default .mdf Attachments

Just so you know I just opened up SQL Server Management studio and I have six attachments to the PlanetWrox database for chapters 14, 15,16,17 and 18. I don't know if that means anything or not.
Reply With Quote
  #7 (permalink)  
Old May 19th, 2013, 02:36 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

I hate to ask the same thing over and over again, but please be specific and provide lots more information. For example, which server do you log in to (LocalDB? SQL Express?) How did you configure IIS? Which account are you using? What happens when you remove the databases you mentioned first? Etc. etc. etc.

Problems like this are tricky to solve over a forum, but impossible to solve without you providing detailed, step by step descriptions of what you're doing and how your system looks.

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!
Reply With Quote
  #8 (permalink)  
Old May 19th, 2013, 11:40 PM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default Okay

For example, which server do you log in to (LocalDB? SQL Express?)

I don't have a version of SQL Express for 2012 only 2008 which sits on the same box as the 2012 database does.
I am not sure what you are asking when which account I used when configuring IIS. I guess I used the local administrator's account for the box that I am on. But I don't have a .SQL express installed for 2012. I can't find it anywhere. It is not listed on the connect to server dialog box that pops up when you first run the SQL Server Management Studio. That might be the problem. So with that being the case I switched the connection strings back to (LocalDB)\v11.0 and took out the .\SqlExpress part out of the connection strings and ran the release version by right clicking on Default.aspx and selecting view in browser and it ran just fine that way. I could browse through all of the pages without any problems. Then when I tried to run that same website in the browser by going to http:\\localhost and trying to access the concert reviews section of the website I got this error:
Code:
Server Error in '/' Application.

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
)
It seems like to me that what we are dealing with here is a SQL server permissions issue.
Reply With Quote
  #9 (permalink)  
Old May 20th, 2013, 06:52 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
I don't have a version of SQL Express for 2012 only 2008 which sits on the same box as the 2012 database does.
Ah, that explains it. The database in App_Data have been created against LocalDB which is SQL Server 2012. The MDF files are not backwards compatible to 2008. I see a few solutions:

1. Just skip this exercise. It's not important in itself; it just shows how to configure SQL Server.

2. Uninstall 2008 Express and then install 2012 Express.

3. Install 2012 Express side by side with 2008 Express but give it a different instance name during installation such as .\SqlExpress2012. Then update the connection strings to use this new named instance of SQL Server 2012.

4. Attach your databases to your existing 2012 installation. Then update the connection strings to target that server and point the Initial Catalog to "PlanetWrox" rather than using the AttachDbFileName. Appendix B shows how to do this.

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!
Reply With Quote
  #10 (permalink)  
Old May 20th, 2013, 08:28 AM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default So what about?

While I have you here I just thought I might ask. Can you not do the following for deployment? also:
Select the project in the Solution explorer window and then build the select Build Deployment Package from the Project menu, then will not VS build the project and generate a zip file that contains the files required to deploy the application and any database schema and the data required that was specified when the project was prepared? Then once that is done start the IIS manager tool and navigated to where the Release is on the hard drive and then click Import Application link in the right of the IIS manager window? Is that not the way to do it or is there more one way to skin the proverbial cat as the old saying goes, when it comes to deployment of .NET web applications ?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection String sumith ASP.NET 2.0 Basics 1 December 26th, 2008 08:30 PM
connection string Sheraz Khan ASP.NET 2.0 Basics 3 July 5th, 2007 08:33 AM
Connection String aadz5 JSP Basics 1 January 24th, 2005 04:36 AM
Connection string tlamazares SQL Server ASP 1 March 29th, 2004 05:16 PM
connection string aadz5 ASP.NET 1.0 and 1.1 Basics 4 October 20th, 2003 08:43 AM



All times are GMT -4. The time now is 05:10 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.