I am using Visual Developer 2008 Express Edition for the first time, and I keep getting the following error below. The site allows anyone to enter with a valid username and password, but even when I logoff the site I get the same error....like the memory or database is not getting refreshed. I would think that when I initially compile the site that anything left in memory would be flushed out. Can someone please help me to figure this out.
Thanks,
Ramell P.S. The site is programmed using C#
Unable to cast object of type 'System.DBNull' to type 'System.String'.
Description: 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.
Exception Details: System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'.
Source Error:
Line 57: } Line 58: Line 59: <asp:Label ID="Label2" runat="server" Text='<%# SharedRoutines.truncate((string)Eval("description")) %>' /> Line 60: <a href='<%# "News_View.aspx?Articleid=" + Convert.ToString(Eval("ID")) %>'>read more Line 61: »</a>
Source File: e:\Web Site Portfolio\Greater_Mt_Olive\WebPartControls\RecentNews.ascx Line: 59
Stack Trace:
[InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'.] ASP.webpartcontrols_recentnews_ascx.__DataBinding__control8(Object sender, EventArgs e) in e:\Web Site Portfolio\Greater_Mt_Olive\WebPartControls\RecentNews.ascx:59 System.Web.UI.Control.OnDataBinding(EventArgs e) +99 System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +206 System.Web.UI.Control.DataBind() +12 System.Web.UI.Control.DataBindChildren() +204 System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +216 System.Web.UI.Control.DataBind() +12 System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +130 System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +454 System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +53 System.Web.UI.WebControls.Repeater.DataBind() +72 System.Web.UI.WebControls.Repeater.EnsureDataBound() +55 System.Web.UI.WebControls.Repeater.OnPreRender(EventArgs e) +12 System.Web.UI.Control.PreRenderRecursiveInternal() +86 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.WebControls.WebParts.WebPart.PreRenderRecursiveInternal() +62 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041
![]() |
0 |
![]() |
Change your binding code like so
<asp:Label ID="Label2" runat="server" Text='<%# SharedRoutines.truncate(Eval("description").ToString()) %>' />I believe using ToString instead of casting to a string will return an empty string for DBNull. There is no quick way for me to test this though. If that doesn't work you can set the value using a conditional like so...
SharedRoutines.truncate( (Eval("description") == System.DBNull)? "" : Eval("description").ToString() );Basically if DBNull, return empty string else continue.Hope this helps.
![]() |
0 |
![]() |
FYI, it looks like this code...
(string)Eval("description")
...is failing because "description" is null.
How to fix that?
I am sorry; but, I do not know the code-infront declarative syntax.
In code-behind, it would be something like this...
//Get the value from the database.
string myValue = "";
if (myValue == DBNull.Value)
{
//The value is null and I cannot do this...
//(string)Eval("description")
}
else
{
//The value is not null and I can do this...
//(string)Eval("description")
}
http://www.NetBrainer.com
![]() |
0 |
![]() |
This works...thanks very much. Now I have a new Problem....I'm getting the error message below when I log out of my site (with my username and password), and try to click on any other link afterwards. I notice that there is a temp file that is being referenced on my local drive (c:\Users\Ramell\AppData\Local\Temp\Temporary ASP.NET Files\greater_mt_olive\a7f156ac\57ce8d6c\App_Code.uozotu5o.9.cs). I would assume that the data base connection is trying to reference this temp file to determine the user ID, as opposed to just looking at the user ID in real-time once I have logged off the site. Is there some way that I can get around this?How can I program the site to reset it self once anyone log out of the site?
Thanks,
Ramell
Cannot open database "ClubDB" requested by the login. The login failed.
Description: 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.
Login failed for user 'Ramell-PC\Ramell'.
Exception Details: System.Data.SqlClient.SqlException: Cannot open database "ClubDB" requested by the login. The login failed.
Login failed for user 'Ramell-PC\Ramell'.
Source Error:
Line 2186: this.Adapter.SelectCommand = this.CommandCollection[0]; Line 2187: DataSet.SiteSettingsDataTable dataTable = new DataSet.SiteSettingsDataTable(); Line 2188: this.Adapter.Fill(dataTable); Line 2189: return dataTable; Line 2190: }
Source File: c:\Users\Ramell\AppData\Local\Temp\Temporary ASP.NET Files\greater_mt_olive\a7f156ac\57ce8d6c\App_Code.uozotu5o.9.cs Line: 2188
Stack Trace:
[SqlException (0x80131904): Cannot open database "ClubDB" requested by the login. The login failed. Login failed for user 'Ramell-PC\Ramell'.] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +800131 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932 System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +33 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +172 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +381 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +181 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +173 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +357 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +30 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +494 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105 System.Data.SqlClient.SqlConnection.Open() +111 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121 System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) +162 System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) +107 DataSetTableAdapters.SiteSettingsTableAdapter.GetSiteSettings() in c:\Users\Ramell\AppData\Local\Temp\Temporary ASP.NET Files\greater_mt_olive\a7f156ac\57ce8d6c\App_Code.uozotu5o.9.cs:2188 DevCowSiteSettings.GetSiteSettings() in e:\Web Site Portfolio\Greater_Mt_Olive\App_Code\SiteSettings.cs:49 DevCow.Web.UI.DevCowThemePage.Page_PreInit(Object sender, EventArgs e) in e:\Web Site Portfolio\Greater_Mt_Olive\App_Code\DevCowThemePage.cs:20 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33 System.Web.UI.Page.OnPreInit(EventArgs e) +2062504 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +663
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
![]() |
0 |
![]() |