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

May 18th, 2013, 02:23 PM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
|
|
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="data source=.\SqlExpress;attachdbfilename=|DataDirector y|\PlanetWrox.mdf;integrated security=True;User Instance=True;MultipleActiveResultSets=True;App=En tityFramework"" 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..
|
|

May 19th, 2013, 05:23 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
Last edited by Imar; May 19th, 2013 at 11:04 AM..
|
|

May 19th, 2013, 09:02 AM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
|
|
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="data source=.\SqlExpress;attachdbfilename=|DataDirectory|\PlanetWrox.mdf;integrated security=True;User Instance=True;MultipleActiveResultSets=True;App=EntityFramework"" 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..
|
|

May 19th, 2013, 11:03 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

May 19th, 2013, 11:48 AM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
|
|
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..
|
|

May 19th, 2013, 11:57 AM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
|
|
.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.
|
|

May 19th, 2013, 02:36 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

May 19th, 2013, 11:40 PM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
|
|
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.
|
|

May 20th, 2013, 06:52 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

May 20th, 2013, 08:28 AM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
|
|
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 ?
|
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 |
|
 |
|