INSERT Command is trying to insert to wrong database. RRS feed

  • Question

  • I have a c# project in Visual studio 2005 that isn't working as expected. All my select statements work and are connecting to the right DB, but whenever I try to insert, it tries to connect to a totally different db, and gives me the message "Server user 'username' is not a valid user in database 'TechniciansTracker'."

    The correct database should be "ARSystem."

    • I have a dataset (dataset2.xsd) that is set up to connect to the right database. The connection string is: "Provider=SQLOLEDB;Data Source=sqlsvr2;Persist Security Info=True;Password=password;User ID=username;Initial Catalog=ARSystem"

    • I have searched through all the files in my project and find no reference to "TechniciansTracker" anywhere.

    • I have tried explicitly stating the DB name in my INSERT statement, like this: "INSERT INTO [ARSystem].[dbo].[Ticket] but it still gives me the error about the TechniciansTracker. 
    Any help is appreciated. If you need any code I can provide that too.
    Thursday, March 27, 2008 2:21 PM

All replies

  • Do you have a table adapter that performs the insert operation or is it a simple statement?

    Please post:

    • your dataset2.xsd file
    • config file containing connection strings
    • the exact insert query since there might be an escape problem.
    • the code that calls your insert statement


    Thursday, March 27, 2008 5:46 PM
  • Is there an trigger on the "Ticket" table that is trying to do something in the "TechniciansTracker" database?

    Wednesday, April 2, 2008 5:55 PM
  • Sounds like you have multiple connection strings stored somewhere in your application. Try to scan code for connection strings and also check what you have in configuration file and settigns file of your application.

    Thursday, April 3, 2008 9:53 AM
  • Try calling ChangeDatabase method before issueing the insert command.
    Thursday, April 3, 2008 4:48 PM