1

I am using Linq against a DBML file, I believe this is Linq2SQL.

During development, I used a staging database called "Stage", and am now using a different database. My rights to the staging database have been removed.

When I use the following connection string

 <add name="Management_Report_Emailer.Properties.Settings.DWConnectionString"
            connectionString="Data Source=biqasql01;Initial Catalog=DW;Integrated Security=True"
            providerName="System.Data.SqlClient" />
    </connectionStrings>

and then pass that inner string to Linq

DWDataContext DWctx = new DWDataContext(CurrentServerConnection);

Some of my linq queries work, some dont. The one that doesn't work throws this exception

Error The server principal "mydomain\myusername" is not able to access the
database "DWStage" under the current security context.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolea
n breakConnection)
   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 cm
dHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, Tds
ParserStateObject stateObj)
   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, Run
Behavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBe
havior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehav
ior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult
 result)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehav
ior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, S
tring method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behav
ior)
   at System.Data.Common.DbCommand.ExecuteReader()
   at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo
 queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs
, ICompiledSubQuery[] subQueries, Object lastResult)
   at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryI
nfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompile
dSubQuery[] subQueries)
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider
.Execute(Expression query)
   at System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable<T>.Get
Enumerator()
   at Management_Report_Emailer.Program.Main(String[] args) in C:\dev\Management
ReportMail\Management Report Emailer\Program.cs:line 181

QUESTION

Why the heck is it trying to access the wrong database "DWStage" ??? I've reduced this to only four lines of code in this application, none of them reference that string. I did a file search for that string and can't find it anywhere.

4
  • Did your DataAccess code reside in another project? Commented Jan 13, 2011 at 18:34
  • Everything is in the same project. I step into the app and there is practically nothing that runs before the exception. I'm stepping using F11, and don't use any wacky setters... Commented Jan 13, 2011 at 18:53
  • Did you search with * filter to search all of the files in your solution? Open the Search in Files and select the solution path, then hit the search, maybe you see different result. Commented Jan 13, 2011 at 19:26
  • I used AgentRansack, a aggressive file searcher that hasn't failed me yet (even binary files). Perhaps the string is uuencoded somewhere.. Commented Jan 13, 2011 at 20:03

1 Answer 1

1

The correct answer is : Check your view!

I'm using a table in a different database in the referenced view, that my account doesn't have access to. SQL is correctly reporting that I can't view that other table.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.