我是一個sql服務器的新手,我無法解決此問題。我一直在尋找2天,我完全失去了。無效的對象名稱'TableName'
這是我在加載頁面時得到的錯誤。
無效的對象名稱表名'
描述: 當前Web請求執行過程中發生了未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。
異常詳細信息:System.Data.SqlClient.SqlException:無效的對象 名 '表名'。
這是我的代碼
private void BindListView()
{
string ConString = System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
using (SqlConnection SConnection = new SqlConnection(ConString))
{
using (SqlCommand SCommand = new SqlCommand())
{
SCommand.CommandText = "SELECT * FROM TableName";
SCommand.Connection = SConnection;
using (SqlDataAdapter SDAdapter = new SqlDataAdapter(SCommand))
{
DataTable DTable = new DataTable();
SDAdapter.Fill(DTable); //This is the line where i am getting error
NewsList.DataSource = DTable;
NewsList.DataBind();
}
}
}
}
這是我的連接字符串。
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient"/>
該代碼工作正常,我的電腦與localhost。但是,當網站託管它不工作。
在主機上,我發現了數據庫連接字符串,我更換了上面這web.config
文件。但我得到上面的錯誤
<add name="ApplicationServices"
connectionString="Data Source=.\MSSQLSERVER2014;Integrated Security=True;User ID=user;Password=password;Connect Timeout=15;Encrypt=False;Packet Size=4096"
providerName="System.Data.SqlClient"/>
我認爲問題是連接數據庫,我不知道該怎麼做。
請幫
異常告訴你它無法在數據庫中找到名爲「TableName」的表。 – elloco999
'TableName'表是否存在於本地主機數據庫和託管數據庫中? – DVJex
您嘗試在同一臺服務器上連接到的數據庫? – Rohit