无效的对象名称“项目”错误。没有处理例外情况 [英] Invalid object name 'Project' error. Exception was not handled

查看:97
本文介绍了无效的对象名称“项目”错误。没有处理例外情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

static void Main(string[] args)
{
   SqlConnection conn = new SqlConnection("Data Source=DEV156-64; Initial Catalog=master; User Id=sa;Password=BeeSys;");
          
   SqlDataReader rdr = null;
   conn.Open();
   SqlCommand cmd = new SqlCommand("select * from Project", conn);

   rdr = cmd.ExecuteReader();

   while (rdr.Read())
   {
      Console.WriteLine(rdr[0]);
      Console.ReadLine();
   }
           
   if (rdr != null)
   {
      rdr.Close();
   }
   if (conn != null)
   {
      conn.Close();
   }
}

推荐答案

好像你要连接 master 根据以下代码的数据库...

Seems like you are connecting to master Database according to the following code...
SqlConnection conn = new SqlConnection("Data Source=DEV156-64; Initial Catalog=master; User Id=sa;Password=BeeSys;");



然后你从 Project 表中获取数据。


Then you are getting data from Project Table.

SqlCommand cmd = new SqlCommand("select * from Project", conn);





根据错误信息,很明显Project没有存在于 master 数据库中。请在连接字符串中提及正确的数据库。



According to the Error Message, it is quite clear that Project does not exist inside the master Database. Please mention the correct Database in the connection string.


这篇关于无效的对象名称“项目”错误。没有处理例外情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆