简体   繁体   English

无效的对象名称“ CAccounts”

[英]Invalid object name “CAccounts”

I keep getting this error: 我一直收到这个错误:

Invalid object name "CAccounts". 无效的对象名称“ CAccounts”。

and the code I have is: 我拥有的代码是:

System.Threading.Thread thread = new System.Threading.Thread(() =>
{
    // Set ConnectionString.
    String sConSg =
    "CONNSTRING HERE";

    using (SqlConnection connection = new SqlConnection(sConSg))
    {
        try
        {
            connection.Open();
        }
        catch (Exception exception)
        {
            MessageBox.Show(stat.Text = exception.Message);
        }

        try
        {
            SqlDataReader slrr = null;
            SqlCommand command = new SqlCommand("SELECT ActivationCode FROM CAccounts WHERE ActivationCode = " +
                "'" + _activationcode.Text + "'", connection);
            slrr = command.ExecuteReader();

            while (slrr.Read())
            {
                if (slrr["ActivationCode"].ToString() == _activationcode.Text)
                {
                    MessageBox.Show(slrr["ActivationCode"].ToString(), "AutoOptimise");

                }
                else
                {
                }
            }
        }
        catch (Exception exception)
        {
            MessageBox.Show(stat.Text = exception.Message);
        }
    }

});
thread.Start();

Can somebody please shed some light? 有人可以解释一下吗?

The table CAccounts you're referencing in your select clause probably doesn't exist in the database. 您在select子句中引用的表CAccounts可能在数据库中不存在。 Check that. 检查一下。

See a list of possibilities here: 在此处查看可能性列表:

http://web.archive.org/web/20150519073601/http://sqlserver2000.databases.aspfaq.com:80/why-do-i-get-object-could-not-be-found-or-invalid-object-name.html http://web.archive.org/web/20150519073601/http://sqlserver2000.databases.aspfaq.com:80/why-do-i-get-object-could-not-be-found-or-invalid-对象name.html

I'd suggest these things: 我建议这些事情:

  • check which schema the object CAccounts is under. 检查对象CAccounts在哪个架构下。 Is it dbo or other? dbo还是其他? Does the user have permissions on that schema? 用户是否对该模式具有权限?

  • login to SQL Server via Management Studio. 通过Management Studio登录到SQL Server。 Use the credentials in the connection string that the code is using. 在代码使用的连接字符串中使用凭据。 Paste & run the SQL statement above. 粘贴并运行上面的SQL语句。

  • use SQL Profiler to capture/verify ensure the SQL statement as it crosses to your SQL Server. 使用SQL事件探查器捕获/验证与SQL Server交叉的SQL语句。 Run THAT as an adhoc query against that SQL Server. 针对该SQL Server将THAT作为临时查询运行。

  • are there any funny DNS issues? 是否有任何有趣的DNS问题? Hosts files? 托管文件? Does this happen during debugging or on the app server? 这是在调试期间还是在应用服务器上发生?

  • is the database server name correct? 数据库服务器名称正确吗? ie localhost versus a named server. 即本地主机与命名服务器。 Try addressing by the IP address that you expect it to be run at, just for fun, both in your connection string, and via SSMS. 尝试通过连接字符串或通过SSMS,以您希望其运行的IP地址为寻址。

Instead of CAccounts, I had to label it DATABASENAME.dbo.CAccounts. 我不得不将其标记为DATABASENAME.dbo.CAccounts,而不是CAccounts。

So it would be something like: 所以它会是这样的:

"SELECT * FROM DATABASENAME.db.CAccounts" “选择* FROM DATABASENAME.db.CAccounts”

This might work: 这可能有效:

SqlConnection con = new SqlConnection("Data Source=192.168.1.12;Initial Catalog=Ibrahim;User ID=sa;Password=1412;");
            con.Open();
            SqlCommand cmd = new SqlCommand("insert into Ibrahim.EVC_Activation_Val (Date,Dealer,Transaction_ID,Invoice_ID,Mobile_Num,Quantity_LE) values('" + DateTimePicker1.Value.ToString("yyyy/mm/dd") + "','" + Txtbx1.Text + "','" + Txtbx2.Text + "','" + Txtbx3.Text + "','" + Txtbx4.Text + "','" + Txtbx5.Text  + "')",con);
            cmd.ExecuteNonQuery();
            MessageBox.Show("Saved");
            con.Close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM