1

Okay I know there are a lot of questions regarding this issue but I can't seem to find a solution there. Plus a lot of them were using Hardcode queries but I am using xsd files to connect to the SQL server 2014. Following is the exception:

Error that has been thrown by sqlconnector

And this is my connection string:

Data Source=NLNT832\SQLEXPRESS,2301;Initial Catalog=IPC_DATABASE;Persist Security Info=True;User ID=ipc_sp_user;Password=omr@n123

I checked the table exists, so as the user. I can connect to the database, see the table in the list, run queries from xsd. But whenever I try to run it through C# it throws the above exception.

My C# code is something like this:

using (DSIPCDatabaseTableAdapters.QueriesTableAdapter queries = new DSIPCDatabaseTableAdapters.QueriesTableAdapter()) {
            queries.ChangeConnection(DBUtils.GetInstance.GetConnectionString);

            try
            {
                object o = queries.AddUser(textBox1.Text.ToString(), textBox2.Text.ToString(), comboBox1.SelectedValue.ToString());
                if (o != null)
                    showOptionDialog();
                else
                    MessageBox.Show("Insertion Error!");
            }
            catch (Exception ex) {
                MessageBox.Show(ex.ToString());
            }
        }

Below is the screenshot of the table present in the database and accessible by the username provided.Table present in the database

FYI I urge you to think twice before marking it as a duplicate.

Tarek Saazeb
  • 35
  • 1
  • 11
  • you're going to have to provide more context than that in order to avoid it being flagged as a duplicate. How is your situation any different than this one: http://stackoverflow.com/questions/24621007/invalid-object-name-sql ? – sous2817 Jan 17 '17 at 15:49
  • I did, please check again @sous2817 – Tarek Saazeb Jan 17 '17 at 15:51
  • Where are you opening the connection? – SS_DBA Jan 17 '17 at 15:53
  • You see the `DBUtils.GetInstance.GetConnectionString` it has the `GetInstance` function which calls the `connection.open()` @WEI_DBA – Tarek Saazeb Jan 17 '17 at 15:59
  • @TarekSaazeb, Thank you for clarifying. Can you show a screenshot of the database with the table? And you can see the table using the `ipc_sp_user` login, correct? – SS_DBA Jan 17 '17 at 16:17
  • Have you tried any of the solutions in the link I provided? The first suggestion seems promising (Make sure you're using the correct database. It may be defaulting to the "Master" database, and it doesn't look like you have the full schema for the referenced table.). Is AddUser a method your wrote? If so, perhaps you should post that method as well... – sous2817 Jan 17 '17 at 16:42
  • See the link [link] (http://imgur.com/em0AzKA) @WEI_DBA – Tarek Saazeb Jan 18 '17 at 08:34
  • @sous2817 it's an insert query, yes I wrote the query. Do you have any experience using database tables through XSD? Please see the screenshot I provided. – Tarek Saazeb Jan 18 '17 at 08:36
  • Alright, nevermind guys, I found the solution already. Putting USE "MY_DATABASE_NAME" solved it. But I don't know why. Because as you can see I have other functions as well in `QueriesTableAdapter` and I didn't have to use this. @sous2817 and @WEI_DBA Btw, I get the same error while running a stored procedure. And I still can't solve it. – Tarek Saazeb Jan 18 '17 at 08:42

0 Answers0