locked
Reg:Invalid object name error using ado.net with integrated security RRS feed

  • Question

  • User1784937238 posted

    Hi,

    I am using ado.net to insert the record using the following connection string.

    ConnectionString : Data Source=.\SQLEXPRESS;Initial Catalog=DataBase;Integrated Security=True;User ID=;Password="g+ow=="

    I am able to connect to the DB ,but when we insert the record using the DbCommand (ExecuteNonQuery())"insert into tablename(col1,col2)values(1,2)" then I am getting the error "Invalid Object Name".

    If you use "insert into schemaname.tablename(col1,col2)values(1,2)" then it's working correctly may I know what I did wrong.

    Thanks And Regards,

    P.Sathish Kumar

    Tuesday, June 16, 2015 12:04 PM

Answers

  • User1711366110 posted

    Hi Sathish,
      According to this case, you can refer the following steps which may help you to resolve this issue :

    1.Please make sure that the connection string was defined properly like below :

    "Data Source=.\SQLEXPRESS;Initial Catalog=YourDataBaseName;Integrated Security=True;"

      Click here to refer about SQL connection string syntax.

    2.By default schema name is 'dbo' in sqlserver. If your schemaname is different then you can transfer into dbo like below :

    ALTER SCHEMA dbo TRANSFER YourSchemaName.Yourtablename;

      Click here to refer about Alter Schema syntax.

    3.Or you can set yourschemaname as default schema in sqlserver like below :

    ALTER USER yourUser WITH DEFAULT_SCHEMA = YourSchemaName;

     Click here to refer the above query was discussed/used in this thread.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 17, 2015 4:16 AM