Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

Let me tell you first am new to this coding and creating a web applications.

I used Visual Studio's Default WebForm Template in order to use its Login module and Database.

Now, i have added my own SQL Tables to the Database which is created by the visual studio and also added a new webform to the solution and written some program which connects to my tables. Well, everything works well in the Localhost but when i publish it on to Microsoft Azure & when viewed my page it throws me an error stating "Invalid Object Name 'Table_Name'"

Default.aspx and Login.aspx is working fine with login and logoff but not the one which i have created.

Please, help me understand why this error has occurred.

What I have tried:

Am pasting the error generated when viewed the page.

[SqlException (0x80131904): Invalid object name 'CAPACITY'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +2434922
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5736592
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +285
   System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +3731
   System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +58
   System.Data.SqlClient.SqlDataReader.get_MetaData() +89
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +379
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2026
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +375
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +240
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
   System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +12
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +139
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +136
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +86
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1494
   System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +278
   System.Web.UI.WebControls.ListControl.PerformSelect() +37
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +114
   System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +23
   System.Web.UI.Control.PreRenderRecursiveInternal() +88
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +883



Any Suggestions, Advice and Help will be greatly appreciated.

Thanks
Saikrishna
Posted
Updated 18-Mar-16 1:21am
v2
Comments
Karthik_Mahalingam 18-Mar-16 7:13am    
post your code.
the error is in sql statement
Sinisa Hajnal 18-Mar-16 7:18am    
You're accessing the object Table_Name that is not defined in your published scope. Do you have the database on Azure? Did you check (and/or change) connection string to that published database? Maybe it is as simple as trying to access your local database from the cloud?

Maybe you just made typing error? What is your Table_Name name? try qualifying the name with db schema (such as dbo.Table_Name)
Member 10376341 18-Mar-16 7:25am    
@Sinisa Hajnal. No i didn't change any connection strings. Also Default Login seems working.
You were talking about Published scope, can you please elaborate it.
Member 10376341 18-Mar-16 7:27am    
Here is my Code behind @Karthik Bangalore:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Configuration;

namespace Synch
{
public partial class Centre_Cre : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
string IT_ITES = "SELECT (SELECT Count(case when [IT-ITES1] = 'Approved' then 1 end) FROM Capacity WHERE State = '" + DropDownList1.SelectedValue + "')";
string RETAIL = "SELECT (SELECT Count(case when [RETAIL1] = 'Approved' then 1 end) FROM Capacity WHERE State = '" + DropDownList1.SelectedValue + "')";
string LSC = "SELECT (SELECT Count(case when [LSC1] = 'Approved' then 1 end) FROM Capacity WHERE State = '" + DropDownList1.SelectedValue + "')";
string ESSCI = "SELECT (SELECT Count(case when [ESSCI1] = 'Approved' then 1 end) FROM Capacity WHERE State = '" + DropDownList1.SelectedValue + "')";
string TSSC = "SELECT (SELECT Count(case when [TSSC1] = 'Approved' then 1 end) FROM Capacity WHERE State = '" + DropDownList1.SelectedValue + "')";
string THSC = "SELECT (SELECT Count(case when [THSC1] = 'Approved' then 1 end) FROM Capacity WHERE State = '" + DropDownList1.SelectedValue + "')";
string GJSCI = "SELECT (SELECT Count(case when [GJSCI1] = 'Approved' then 1 end) FROM Capacity WHERE State = '" + DropDownList1.SelectedValue + "')";
string ASCI = "SELECT (SELECT Count(case when [ASCI1] = 'Approved' then 1 end) FROM Capacity WHERE State = '" + DropDownList1.SelectedValue + "')";
string CSDCI = "SELECT (SELECT Count(case when [CSDCI1] = 'Approved' then 1 end) FROM Capacity WHERE State = '" + DropDownList1.SelectedValue + "')";
string APPAREL = "SELECT (SELECT Count(case when [APPAREL1] = 'Approved' then 1 end) FROM Capacity WHERE State = '" + DropDownList1.SelectedValue + "')";
//string TOTAL = "SELECT (SELECT Count(case when [CSDCI1] = 'Approved' then 1 end) FROM Capacity WHERE State = '" + DropDownList1.SelectedValue + "')";
SqlCommand showresult1 = new SqlCommand(IT_ITES, con);
SqlCommand showresult2 = new SqlCommand(RETAIL, con);
SqlCommand showresult3 = new SqlCommand(LSC, con);
SqlCommand showresult4 = new SqlCommand(ESSCI, con);
SqlCommand showresult5 = new SqlCommand(TSSC, con);
SqlCommand showresult6 = new SqlCommand(THSC, con);
SqlCommand showresult7 = new SqlCommand(GJSCI, con);
SqlCommand showresult8 = new SqlCommand(ASCI, con);
SqlCommand showresult9 = new SqlCommand(CSDCI, con);
SqlCommand showresult0 = new SqlCommand(APPAREL, con);
//SqlCommand showresult2 = new SqlCommand(TOTAL, con);

con.Open();
lblstate.Text = DropDownList1.SelectedValue;
lblTOTAL.Text = (Int32.Parse(lblIT.Text) + Int32.Parse(lblRETAIL.Text) + Int32.Parse(lblLSC.Text) + Int32.Parse(lblESSCI.Text) + Int32.Parse(lblTSSC.Text) + Int32.Parse(lblTHSC.Text) + Int32.Parse(lblGJSCI.Text) + Int32.Parse(lblASCI.Text) + Int32.Parse(lblCSDCI.Text) + Int32.Parse(lblAPPAREL.Text)).ToString();

}
}
Richard Deeming 18-Mar-16 9:11am    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

1 solution

As mentioned in comments, you're trying to access a table or view or something in sql that is not actually there. The error says it is "CAPACITY." So, look at your sql and make sure it is right. If you believe it is right then check your connection string to make sure you are pointing to the correct database.
 
Share this answer
 
Comments
Member 10376341 18-Mar-16 7:39am    
How do i view Database Tables in Azure portal?
ZurdoDev 18-Mar-16 7:42am    
https://azure.microsoft.com/en-us/documentation/articles/sql-database-manage-azure-ssms/
Member 10376341 18-Mar-16 7:50am    
You are right i don't see my tables in the Azure Database. But how come i can see default tables?

Also, please let me know what to do next. How should i add my own tables.
ZurdoDev 18-Mar-16 7:52am    
I haven't used Azure yet, but here is a good article: https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-tables/
Member 10376341 18-Mar-16 7:55am    
Thank you for the help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900