SqlException Was Unhandeld By User Code??? (Invalid Object Name CP_ADS')http://forums.asp.net/t/1774761.aspx/1?SqlException+Was+Unhandeld+By+User+Code+Invalid+Object+Name+CP_ADS+Tue, 06 Mar 2012 03:36:11 -050017747614855246http://forums.asp.net/p/1774761/4855246.aspx/1?SqlException+Was+Unhandeld+By+User+Code+Invalid+Object+Name+CP_ADS+SqlException Was Unhandeld By User Code??? (Invalid Object Name CP_ADS') <pre class="prettyprint">private void fillAds() { SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings[&quot;ConnString&quot;].ConnectionString); string strQry = &quot;select AD_TYPE,AD_PATH,AD_URL from CP_ADS where SCREEN_ID='1'&quot;; SqlDataAdapter dad = new SqlDataAdapter(strQry, Conn); DataSet ds = new DataSet(); dad.Fill(ds); TableRow trtop = new TableRow(); TableCell tctop = new TableCell(); TableRow trleft1 = new TableRow(); TableCell tcleft1 = new TableCell(); TableRow trleft2 = new TableRow(); TableCell tcleft2 = new TableCell(); if (ds.Tables[0].Rows.Count &gt; 0) { if (ds.Tables[0].Rows[0][&quot;ad_type&quot;].ToString() == &quot;1&quot;) { tctop.Controls.Add(generateImage(ds.Tables[0].Rows[0][&quot;AD_PATH&quot;].ToString(), ds.Tables[0].Rows[0][&quot;ad_url&quot;].ToString(), 404, 75)); } if (ds.Tables[0].Rows.Count &gt;= 3) { if (ds.Tables[0].Rows[2][&quot;ad_type&quot;].ToString() == &quot;1&quot;) { tcleft1.Controls.Add(generateImage(ds.Tables[0].Rows[2][&quot;AD_PATH&quot;].ToString(), ds.Tables[0].Rows[2][&quot;ad_url&quot;].ToString(), 142, 218)); } } if (ds.Tables[0].Rows.Count &gt;= 4) { if (ds.Tables[0].Rows[3][&quot;ad_type&quot;].ToString() == &quot;1&quot;) { tcleft2.Controls.Add(generateImage(ds.Tables[0].Rows[3][&quot;AD_PATH&quot;].ToString(), ds.Tables[0].Rows[3][&quot;ad_url&quot;].ToString(), 142, 218)); } } if (ds.Tables[0].Rows.Count &gt;0) { if (ds.Tables[0].Rows[0][&quot;ad_type&quot;].ToString() == &quot;2&quot;) { tctop.Text = generateFlash(ds.Tables[0].Rows[0][&quot;AD_PATH&quot;].ToString().Replace(&quot;~/&quot;, &quot;&quot;), 404, 75); ; } } if (ds.Tables[0].Rows.Count &gt;= 3) { if (ds.Tables[0].Rows[2][&quot;ad_type&quot;].ToString() == &quot;2&quot;) { tcleft1.Text = generateFlash(ds.Tables[0].Rows[2][&quot;AD_PATH&quot;].ToString().Replace(&quot;~/&quot;, &quot;&quot;), 142, 218); ; } } if (ds.Tables[0].Rows.Count &gt;= 4) { if (ds.Tables[0].Rows[3][&quot;ad_type&quot;].ToString() == &quot;2&quot;) { tcleft2.Text = generateFlash(ds.Tables[0].Rows[3][&quot;AD_PATH&quot;].ToString().Replace(&quot;~/&quot;, &quot;&quot;), 142, 218); ; } } trtop.Controls.Add(tctop); trleft1.Controls.Add(tcleft1); trleft2.Controls.Add(tcleft2); tblTop.Controls.Add(trtop); tblLeftQuick1.Controls.Add(trleft1); tblLeftQuick2.Controls.Add(trleft2); } } Error:</pre> <h2><i>Invalid object name 'CP_ADS'.</i></h2> <pre class="prettyprint"><span style="font-family: Arial,Helvetica,Geneva,SunSans-Regular,sans-serif;" face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "><span style="font-family: Arial,Helvetica,Geneva,SunSans-Regular,sans-serif;" face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "><b>Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <br /><br /><b>Exception Details: </b>System.Data.SqlClient.SqlException: Invalid object name 'CP_ADS'.<br /><br /><b>Source Error:</b> <br /><br /></span></span></pre> <table width="100%" bgcolor="#ffffcc"> <tbody> <tr> <td> <pre>Line 124: SqlDataAdapter dad = new SqlDataAdapter(strQry, Conn);<br />Line 125: DataSet ds = new DataSet();<br /><span style="color: red;" color="red">Line 126: dad.Fill(ds);<br /></span>Line 127: TableRow trtop = new TableRow();<br />Line 128: TableCell tctop = new TableCell();</pre> </td> </tr> </tbody> </table> <pre class="prettyprint"><span style="font-family: Arial,Helvetica,Geneva,SunSans-Regular,sans-serif;" face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "><br /><b>Source File: </b>c:\CampusPoineer_Praveen_Source_June8_2011\CampusPoineer\Master.master.cs<b> &nbsp;&nbsp; Line: </b>126 <br /><br /></span></pre> 2012-02-28T16:00:25-05:004857689http://forums.asp.net/p/1774761/4857689.aspx/1?Re+SqlException+Was+Unhandeld+By+User+Code+Invalid+Object+Name+CP_ADS+Re: SqlException Was Unhandeld By User Code??? (Invalid Object Name CP_ADS') <p>Hello</p> <p>As far as I seeI think there's something wrong with your sql statementSo plz check whether the columns' names as well as the table names are correctly spelt by pasting the &quot;</p> <pre class="prettyprint">select AD_TYPE,AD_PATH,AD_URL from CP_ADS where SCREEN_ID='1'</pre> <pre class="prettyprint"><span class="str">into SQL Mangement Studio to have a try with</span></pre> 2012-03-01T01:47:43-05:004865272http://forums.asp.net/p/1774761/4865272.aspx/1?Re+SqlException+Was+Unhandeld+By+User+Code+Invalid+Object+Name+CP_ADS+Re: SqlException Was Unhandeld By User Code??? (Invalid Object Name CP_ADS') <p>I was using&nbsp; table name to fetch the data. Now I have changed it to&nbsp; schemaname.table in the statement. It is working fine. But my doubt is why shoould we give schema name for sure? why is it not working with table name?</p> <p>&nbsp;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If I have to make changes to all my sql statement like select * from table to select * from cp.table , what should I do? or do we have any work around for this where all my sql statements consider schema name included by default?</p> 2012-03-06T02:27:45-05:004865326http://forums.asp.net/p/1774761/4865326.aspx/1?Re+SqlException+Was+Unhandeld+By+User+Code+Invalid+Object+Name+CP_ADS+Re: SqlException Was Unhandeld By User Code??? (Invalid Object Name CP_ADS') <p></p> <blockquote><span class="icon-blockquote"></span> <h4>harsharamoju</h4> Now I have changed it to&nbsp; schemaname.table in the statement. It is working fine. </blockquote> <p></p> <p>What does that mean</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>harsharamoju</h4> elect * from table to select * from cp.table</blockquote> <p></p> <p>Why do you want to add &quot;cp&quot;And what's cp</p> <p>Show us your screenshot of your SQL table's schema in the SQL Management Studio</p> 2012-03-06T03:36:11-05:00