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.
*filter to search all of the files in your solution? Open theSearch in Filesand select the solution path, then hit the search, maybe you see different result.