Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8769265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:17:46+00:00 2026-06-13T17:17:46+00:00

Issue: After running an Sql command with SqlCommand() on a database that then inserts

  • 0

Issue:

After running an Sql command with SqlCommand() on a database that then inserts data into another database, all following statements error with ExceptionInvalid object name.

Question:

Why is this happening?

Additional Information:

I know how to fix it by adding The Temp database name before the table on the select portion but since it is being run in the context of that database that shouldn’t be necessary and is not when I run the statements individually in SQL management studio

Program Logic:

  1. Create and fill temp database (All tables ASI_…)
  2. In context of temp database select data and then insert it into another database (@AcuDB)
  3. Repeat Step 2 for X queries

Insertion code:

if (TempD.State == System.Data.ConnectionState.Closed) TempD.Open();
                            Command = new SqlCommand(temp, TempD);
                            Command.CommandTimeout = 0;
                            Command.ExecuteNonQuery(); 

Sample Sql being run that errors after previous similar statement:

insert into @AcuDB..Batch (CompanyID,BranchID,
Module,BatchNbr,CreditTotal,DebitTotal,ControlTotal,CuryCreditTotal,CuryDebitTotal,CuryControlTotal,CuryInfoID,LedgerID,BatchType,Status,AutoReverse,AutoReverseCopy,OrigModule,OrigBatchNbr,DateEntered,Released,Posted,LineCntr,CuryID,ScheduleID,NoteID,CreatedByID,CreatedByScreenID,CreatedDateTime,LastModifiedByID,LastModifiedByScreenID,LastModifiedDateTime,Hold,Description,Scheduled,Voided,FinPeriodID,TranPeriodID)
select 2,
1,Module,BatchNbr,CreditTotal,DebitTotal,ControlTotal,CuryCreditTotal,CuryDebitTotal,CuryControlTotal,i.CuryInfoID,
isnull((select a.LedgerID from @AcuDB..ledger a where a.LedgerCD =
b.LedgerID),0)
[LedgerID],BatchType,Status,AutoReverse,AutoReverseCopy,OrigModule,OrigBatchNbr,
DateEntered
[DateEntered],Released,Posted,LineCntr,b.CuryID,ScheduleID,NoteID,
‘B5344897-037E-4D58-B5C3-1BDFD0F47BF9’ [CreatedByID], ‘00000000’
[CreatedByScreenID], GETDATE() [CreatedDateTime],
‘B5344897-037E-4D58-B5C3-1BDFD0F47BF9’ [LastModifiedByID], ‘00000000’
[LastModifiedByScreenID], GETDATE()
[LastModifiedDateTime],Hold,Description,Scheduled,Voided,b.FinPeriodID,TranPeriodID
from Temp..ASI_GLBatch b inner join @AcuDB..CurrencyInfo i on
i.CuryEffDate = b.DateEntered cross join @AcuDB..glsetup g where
b.companyID = @CpnyCD and b.branchID = @BranchCD

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:17:48+00:00Added an answer on June 13, 2026 at 5:17 pm

    Going across databases like this is always precarious due to the way SQL will try to imply contexts. In this case, unless @AcuDB contains the fully-qualified address that includes both the database and the schema, you’re going to get errors because of the way you’re switching contexts around. Get a reading on what @AcuDB contains and try to run the batch in a stored procedure. Set up a separate instance to sandbox the scenario if you have to. The C# end of this is going to continue to complicate things until you cut it out for a little bit and make sure your SQL is good. After you’re sure it’s okay, integrate it back into the C# code and work from there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm running into an interesting issue implementing session ID rolling after log-in/change of
Currently GDB has an issue following child processes after a fork. A work around
I'm having an issue implementing an excel feature I'm after, this is my data
I'm having a memory leak issue in a service program that runs SQL scripts
I'm running into a weird issue with Entity Framework in .NET 3.5 SP1 within
first some data: we are using Oracle 11g databases. A primary database running on
I am not able to understand the issue with the following SQL query. I
I ran into an issue with some third party software that we use to
I have a database with a few tables running on SQL Server 2008, and
I've experienced today strange issue. One of my projects is running .NET + SQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.