[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Connecting to SQL Server from ASP.NET web page

Posted on 2014-07-11
6
Medium Priority
?
361 Views
Last Modified: 2014-07-16
I have a SQL database that I access through ASP.NET to return XML. This is working fine on another server. I backed up that database on the other server and restored it to my local server, which should have identical setup. But when I run the ASP.NET page to retrieve data, I get the error message below. The login itself is not failing, which is Windows Authentication, because I can connect to the database using SQL Server Management Studio and run a query. IIS has impersonate set to true. Here is the error I receive from the ASP.NET web page.

Cannot open database "AAA" requested by the login. The login failed. Login failed for user 'BBB\cccc'. CommandText: CEConfig.Facility_List CommandType: 4 Parameter: @FacilityID Value: Parameter: @Name Value: Stack: at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at SQLDatabaseConnector.DatabaseConnections.ExecuteReader(SqlCommand oCmd) Event Log Error: Cannot open log for source 'SQLDatabaseConnector'. You may not have write access.
0
Comment
Question by:Regnillobian
  • 4
  • 2
6 Comments
 

Author Comment

by:Regnillobian
ID: 40191067
I do have write access to directory C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL. I created a text file there and modified it.
0
 
LVL 21

Assisted Solution

by:Randy Poole
Randy Poole earned 100 total points
ID: 40191141
In SQL Management Studio open up the database and select the security node.
Remove the user "BBB\cccc" from there if it exists, add a new user and select the same user and give them the permissions.  It looks like although the account is there it is pointing to an ID on the other SQL Server which is not the same on this one.
0
 

Accepted Solution

by:
Regnillobian earned 0 total points
ID: 40191353
I tried that and it did not change anything. After spending a couple more hours on this, we found out the database was restored to a slightly different name, which is why our connection was not working. So SQL was telling us login failed, but should have said DB did not exist. Thanks for your assistance.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 21

Expert Comment

by:Randy Poole
ID: 40191356
lol, that can do it :P
0
 

Author Comment

by:Regnillobian
ID: 40191361
It was also helpful to check the SQL error log. That got us on the right track.
0
 

Author Closing Comment

by:Regnillobian
ID: 40198824
It was also helpful to check the SQL error log. That got us on the right track.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question