Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : 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 October 14th, 2013, 02:57 PM
Registered User
 
Join Date: Jan 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Chapter 16 - problem in connecting VS to SQL Server

Hello,
I have a problem in connecting the SQL Server data base to Visual Studio.
I'll be very grateful if someone can help me.

My Planet Wrox site worked until chapter 15 included, it means that both VS and SQL server are working.
The problem is when I add a Login control to a page and try to log in with random user and password.
I get the following Yellow Screen Of Death:


Code:
Stack Trace: 

[SqlException (0x80131904): 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: 26 - Error Locating Server/Instance Specified)]
   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.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5308555
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +145
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +920
   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) +5311099
   System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +38
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +5313314
   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.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +76

[HttpException (0x80004005): Unable to connect to SQL Server database.]
   System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +131
   System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +89
   System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +27
   System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +386

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18045
Inside the App_Data folder the aspnetdb.mdf is not created.

From Visual Studio >> WebSite >> Asp.Net Configuration >> Security >> after a while I get this message:

"There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help in diagnosing the problem: Unable to connect to SQL Server database."

And also if I double click the PlanetWrox.mdf file in the Solution Explorer I get this:
"Connections to SQL Server database files (.mdf) require SQL Server 2005 Express or SQL Server 2008 Express to be installed and running on the local computer. The current version of SQL Server Express can be downloaded at the following URL: ..."


This is my connection string:
Code:
<connectionStrings>
	<add name="PlanetWrox_DB" providerName="System.Data.SqlClient" connectionString="Server=localhost; User ID=sa; Password=xyz; Database=PlanetWrox_Final;" />
</connectionStrings>
I'm using these programs on a Windows 8 local machine:
- Visual Studio 2010 paid version (trial)
- SQL Server 2008 R2 (SP2) - Express Edition (64bit) (up and running)

I've done these operations:

- Attached the data base to SQL Server Management Studio
- Enabled Named Pipes and TCP/IP from SQL Server Configuration Manager
- Granted read/write permissions to the App_Data folder for all the users
- Created a new WebSite and performed the same operations using another DB
- Read Appendix B of the book
- Searched on Google and Wrox forum

I noticed that when I log in to SQL Server Management Studio the Server Name is "SRB-PCP" that is the name of my computer.
Instead in the book the name is computername\SQLEXPRESS.
I wonder if there's something wrong in my installation.

Thanks in advance for your help.
 
Old October 15th, 2013, 06:06 AM
Registered User
 
Join Date: Jan 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up fixed (I hope!)

After a good sleep and a coffee I re-read Appendix B from page 771 and I think I found the solution:
  • launched aspnet_regsql.exe to enable Application Services in the main data base (ok, I could have used a separate db)
  • modified the web.config as follows
Code:
<clear />
	<add name="PlanetWrox_DB" providerName="System.Data.SqlClient" connectionString="Server=localhost; User ID=sa; Password=xyz; Database=PlanetWrox_Final;" />
		<add name="LocalSqlServer" providerName="System.Data.SqlClient" connectionString="Server=localhost; User ID=sa; Password=xyz; Database=PlanetWrox_Final;" />
(of course on production environment I won't use "sa" user)

Now I can open Asp.Net Configuration >> Security
and if I try to login to the site I get "Your login attempt was not successful. Please try again." as expected.

I hope it's all fixed so I can go on studying this great manual.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem connecting to sql server rajanikrishna ASP.NET 2.0 Basics 1 September 5th, 2007 04:47 PM
URGENT:Connecting SQL server through Proxy server abhowal Pro VB Databases 2 January 9th, 2006 01:47 PM
URGENT:Connecting SQL server through Proxy server abhowal SQL Server 2000 3 November 30th, 2005 04:22 AM
problem 2 connecting SQL Server 200 using ASP.NET nagen111 ADO.NET 5 February 16th, 2005 01:26 AM
I have problem connecting to SQL Server 2000 sp3 ctanchan SQL Server 2000 0 September 11th, 2003 07:35 PM





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