Linq to sql 很郁闷的一个问题:: System.Data.SqlClient.SqlException: 对象名 无效

paypay2012 2012-05-22 09:28:28
确认数据库里这个表是存在的,而且我也尝试过新建数据表,但是一直提示:: System.Data.SqlClient.SqlException: 对象名 'dbo.UserGongqiu' 无效。

我新建一个:UserGongqiu2表,也提示 System.Data.SqlClient.SqlException: 对象名 'dbo.UserGongqiu2' 无效。

我可能怀疑漏掉了某段代码,把另外正常的代码,复制过来,字段名称都一样,只是数据库表名称不一样,保存后,还是提示同样的问题。

我在在SQL里新建查询,也能查到数据库表内的数据。

老郁闷的了。


...全文
1028 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
LLL_CUIT 2014-12-23
  • 打赏
  • 举报
回复
怎么添加权限 我也搞了好几天了。。。
三碗猪脚 2014-03-10
  • 打赏
  • 举报
回复
这个要MARK一下
淘气小浩 2012-05-30
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 的回复:]
问题搞定了,一共搞了2天一夜,最后发现原来是数据库的读取权限不够,太怀疑自己了,一直以为自己写的代码上的问题。
[/Quote]
楼主我也遇到这个问题求教怎么解决啊 读取权限怎么添加啊
paypay2012 2012-05-26
  • 打赏
  • 举报
回复
问题搞定了,一共搞了2天一夜,最后发现原来是数据库的读取权限不够,太怀疑自己了,一直以为自己写的代码上的问题。
paypay2012 2012-05-23
  • 打赏
  • 举报
回复

[SqlException (0x80131904): 对象名 'dbo.UsergongQiuinfo' 无效。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1950890
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846875
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
System.Data.SqlClient.SqlDataReader.get_MetaData() +83
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
System.Data.Common.DbCommand.ExecuteReader() +12
System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) +332
System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) +113
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +344
System.Data.Linq.Table`1.System.Linq.IQueryProvider.Execute(Expression expression) +49
System.Linq.Queryable.Single(IQueryable`1 source, Expression`1 predicate) +301
Cnslc.showinfo.Page_Load(Object sender, EventArgs e) in e:\塑料网改版\wwwroot\Cnslc\Cnslc\showinfo.aspx.cs:18
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627



paypay2012 2012-05-23
  • 打赏
  • 举报
回复
我核对了N遍了,确认是没写错的。我换成其他一张字段相同的表,就正常的。就这个表,提示没有找到这张表,但是这张表,我真实存在的。
q107770540 2012-05-23
  • 打赏
  • 举报
回复
重新映射.dbml
重新生成解决方案
shux02 2012-05-23
  • 打赏
  • 举报
回复
仔细看你的连接字符串,Initial Catalog你肯定写错了。
paypay2012 2012-05-23
  • 打赏
  • 举报
回复
求答案
anzhiqiang_touzi 2012-05-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
有dbo出现以上错误。

我特意去掉dbo,也同样出现以上错误。

但是我用sql = select * from UserGongqiu ,在asp.net中能查出数据。

但是我换成另外一张表名,就成功查询到记录。
[/Quote]
孟子E章 2012-05-23
  • 打赏
  • 举报
回复
你要记住,计算机是不会撒谎的
  • 打赏
  • 举报
回复
重新映射一遍。
paypay2012 2012-05-23
  • 打赏
  • 举报
回复
求救,搞了两天了,还没搞定
paypay2012 2012-05-23
  • 打赏
  • 举报
回复
namespace DataLib.DataLinq
{
[Table(Name = "dbo.UsergongQiuinfo")]
public class UsergongQiuinfo : INotifyPropertyChanging, INotifyPropertyChanged
{
private int _id;
private int _ClassId;
private int _SmallId;
private string _Title;
private string _AddTime;
private string _NeiRong;

private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(string.Empty);

public event PropertyChangedEventHandler PropertyChanged;

public event PropertyChangingEventHandler PropertyChanging;

protected virtual void SendPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}

protected virtual void SendPropertyChanging()
{
if (this.PropertyChanging != null)
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}
}

以上是类操作
using System;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Configuration;

namespace DataLib.DataLinq
{
[Database(Name = "New_yysl")]
public class JDDataContext : DataContext
{
private static MappingSource mappingSource = new AttributeMappingSource();

public XJDataContext()
: base(ConfigurationManager.ConnectionStrings["New_YYslConnectionString1"].ConnectionString, mappingSource)
{
}

public XJDataContext(IDbConnection connection)
: base(connection, mappingSource)
{
}

public XJDataContext(string connection)
: base(connection, mappingSource)
{
}

public XJDataContext(IDbConnection connection, MappingSource mappingSource)
: base(connection, mappingSource)
{
}

public JDDataContext(string connection, MappingSource mappingSource)
: base(connection, mappingSource)
{
}
public Table<DataLib.DataLinq.UsergongQiuinfo> UsergongQiuinfo
{
get
{
return base.GetTable<DataLib.DataLinq.UsergongQiuinfo>();
}
}


}
}


。。。。。。。。方法

this.art = this.db.NewsInfo.Single<NewsInfo>(c => c.id == NewsId);


查询。。。。。。。。。。


但是一直提示:对象名 'dbo.UsergongQiuinfo' 无效。


如果我把:dbo.UsergongQiuinfo 表dbo.NewsInfo 就能成功查询。


/////////////////////采用酷睿2代处理器的分割线///////////////////////////////////////

起初我怀疑是数据库表,出了问题,之后我用sql = select * from UsergongQiuinfo 能调出数据。


很郁闷的问题,搞了10多个小时,搞不定。
paypay2012 2012-05-23
  • 打赏
  • 举报
回复
有dbo出现以上错误。

我特意去掉dbo,也同样出现以上错误。

但是我用sql = select * from UserGongqiu ,在asp.net中能查出数据。

但是我换成另外一张表名,就成功查询到记录。
Astpiy 2012-05-23
  • 打赏
  • 举报
回复
如果你用的LinQ to sql ,在ASP。NET中使用话,应该没有前面的dbo.

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧