Last post Jun 17, 2015 04:16 AM by Edwin Guru Singh
Jun 16, 2015 12:04 PM|sathish.career|LINK
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,
Jun 17, 2015 04:16 AM|Edwin Guru Singh|LINK
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;
to refer the above query was discussed/used in this thread.