.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

DataBase broken. deadline in a few hours, specified cast is not valid. What do i do

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net

There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.

The following message may help in diagnosing the problem: Specified cast is not valid.


I'm not sure how it happened but after changing a column in my AccommodationComment table from memberId to username I tested it and all pages which have to do with selecting current user or any user says:


System.InvalidCastException was unhandled by user code
  Message=Specified cast is not valid.
       at System.Data.SqlClient.SqlBuffer.get_SqlGuid()
       at System.Data.SqlClient.SqlDataReader.GetGuid(Int32 i)
       at System.Web.Security.SqlMembershipProvider.GetUser(String username, Boolean userIsOnline)
       at System.Web.Security.Membership.GetUser(String username, Boolean userIsOnline)
       at System.Web.Security.Membership.GetUser()
       at Actions.getUse

View Complete Post

More Related Resource Links

My Sql server 2005 Database in recovery mode for 3 -4 hours every day

Hi , Some of our Sql Server 2005 databases remain in recovery mode after midnight for almost 3 to 4 hours. So when my application access them error "Databse in recovery" and for same database this happens again and again every night. Please suggest why and how this can be solved?

database.Schemas.Contains not valid for SQL 2000

database.Schemas.Contains(LoginName) doesn't appear to work with SQL 2000 - is there an alternative method? I'm checking for the existance of the Login and User and droping them if they exist via:   Dim xServer As Server = New Server(ServerName & "\" & Instance) Dim db As New Database(xServer, Database) db = xServer.Databases(Database) If db.Schemas.Contains(LoginName) Then db.Schemas(LoginName).Drop() End If If db.Users.Contains(LoginName) Then db.Users(LoginName).Drop() End If Which errors (Operation not supported on SQL Server 2000.) on db.schemas.contains.

Databind on Gridview throwing System.InvalidCastException. Specific Cast Not Valid

Hello, I am working on a web app where when the user enters data into a text box and presses a filter radio button it should filter the Gridview on the page to the criteria entered.  I have done this before in previous applications with the same code listed below, but for some reason I am now getting the InvalidCastExeption error.  Any help would be appreciated, the source database is SQL and the data field is set to nvarchar and I am using a string to compare as you will see in the code.  I am just unsure why this worked in the past and is not working in this scenario. Thanks, Pete protected void filterLName_CheckedChanged(object sender, EventArgs e) { SHCDataContext existingCustomers = new SHCDataContext(); var filterExistingCustomers = existingCustomers.Customers.Where(c => c.custLastName.Contains(lNameTB.Text.ToString())); displayCustGV.DataSource = null; displayCustGV.DataSourceID = null; displayCustGV.DataSource = filterExistingCustomers; displayCustGV.DataBind(); }   Here is the stack trace....  Specified cast is not valid. 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.I

[Odd]Specified cast is not valid exception

protected float getUserBalance() { string AccountNo = Session["AccNo"].ToString(); myConnection.Open(); float balance = 0; try { OleDbCommand getBalance = new OleDbCommand("Select Balance from BankTransaction where AccountNo = '" + Session["AccNo"] + "'", myConnection); //OleDbDataReader rdrBalance = getBalance.ExecuteReader(); //while (rdrBalance.Read()) //{ // balance = rdrBalance.GetFloat(0); //} balance = float.Parse(getBalance.ExecuteScalar().ToString()); } catch { balance = 0; } myConnection.Close(); return balance; } ===============These are my codes, and it work fine, balance will has a right value, but if I comment the line "balance = float.Parse(getBalance.ExecuteScalar().ToString());"and decomment the 5 lines above, get rid of try catch, I get the error:"Specified cast is not valid"Here is the some informations when I addwatch rdrBalance-        rdrBalance    {System.Data.OleDb.OleDbDataReader}    System.Data.OleDb.OleDbDataReader+        base    {System.Dat

"The Database Engine instance you selected is not valid for this edition of Reporting Services" erro

Hi there, I have developed some reports using Visual Studio and everything worked fine in the office. Now I'm trying to deploy them on my customer PCs but this process keeps failing. These reports can be built and even previewed within Visual Studio but they cannot be deployed. Here is the error message I get: ----------------------------------------- The feature: "The Database Engine instance you selected is not valid for this edition of Reporting Services. The Database Engine does not meet edition requirements for report data sources or the report server database." is not supported in this edition of reporting services. ---------------------------------------- The versions of the software on my customer machines are: SQL Server Enterprise 9.0.3282 SQL Server 2005 Management Studio 9.00.4035 SQL Server 2005 Reporting Services Designers 9.00.4035.00 Visual Studio 2005 8.0.50727.42 I believe that changing the edition of the Reporting Services from Designers to Enterprise should fix the deployment error but I did not find a way or setup files to do so. Many thanks in advance for your help!

Restore error: specified cast is not valid

I've got a database from a client (SQL 2008) and when I try and restore the database to my server, I get the following error: specified cast is not valid...

I get the error as I browse for and select the backup file.

Please help!!!

Specified cast is not valid



I have a stored proc. When i execute this proc with correct data from front end i get no error.

However, when i execute the proc with incorrect data i am getting an error

"specified cast s not valid"

I am using SQL server 2008

and below is my proc

USE [AAVouchers_Dev02]
/****** Object:  StoredProcedure [dbo].[USP_UploadData]    Script Date: 10/20/2010 13:28:08 ******/
ALTER proc [dbo].[USP_UploadData]
    @FileName varchar (100),
    @CorporateID bigint,
    @CreatedBy bigint,
    --@tbl_FileData tbl_FileData  READONLY
    @data Varchar(max),
    @sendMail Bit =0
DECLARE @intError as int,
      @strError as varchar(max),
      @intFILEID int
SET  @intError = 0
SET @strError = 'No Error'

DEclare @data_xml XML = @data


 DECLARE @ErrorTMP TABLE(IntError bigint,StrError Varchar(250))

Begin Try
--check Corpor

Specified cast is not valid during using LINQ


I am having problem, Please help me guys .....

these are the errors:

Server Error in '/FYPasp' Application.
Specified cast is not valid.
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: Specified cast is not valid.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidCastException: Specified cast is not valid.]
   System.Data.SqlClient.SqlBuffer.get_Int32() +5002837
   System.Data.SqlClient.SqlDataReader.GetInt32(Int32 i) +38
   Read_DynamicClass1(ObjectMaterializer`1 ) +322
   System.Data.Linq.SqlClient.ObjectReader`2.MoveNext() +32
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +327
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +58

These are the codes:

string metric = Session["ID"].ToString();
            string status = null;
            var onlineStud = db.students.Single(s => s.metricNo.Equals(metric));


Database is "in recovery" for 3 hours



I booted a server today and it stuck in recovery state. It is SQL2005.  It is 10TB database. Error log for SQL Server doesn't show the progress. I only found "Starting up database 'MyDB'" .  How may I check what is going on.

-- this query shows percent completed 0 for all processes

select der.session_id, der.command, der.

Sys.WebForms.PageRequestManagerServerErrorException - Specified cast is not valid



I'm getting the error in the subject whenever I run my application.  I think that it may be related to this:  http://forums.asp.net/p/1038043/1438409.aspx#1438409 and since I have <compilation debug="true" />, I think setting that to false may aid not getting this, as is what it seems as if I read.  So, Is that correct, or is this related to something else?


Specified cast is not valid.


I am interfacing a .NET Web Service using gSOAP. All operations in the WS take a "layout" parameter whose type is:

<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="foo:bar:replaced" id="NDSLayout">
<xs:element msdata:IsDataSet="true" msdata:UseCurrentLocale="true" name="NDSLayout">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Layout">
<xs:element minOccurs="0" name="FIELD" type="xs:string"/>
<xs:element minOccurs="0" name="INCLUDE" type="xs:boolean"/>
<xs:element minOccurs="0" name="CRITERIA" type="xs:string"/>

BinaryFormatter.Deserialize: specified cast is not valid


I'm trying to run code like this.

Declare custom data type

    public struct Configuration
      public int a;
      public string[] b;
      public string c;

Serialize data to the file

      Configuration config;
      // Assign values to config 
      // Serialize data
      FileStream fs = new FileStream(configFile, FileMode.Create);
      BinaryFormatter formatter = new BinaryFormatter();
        formatter.Serialize(fs, config);
      catch (SerializationException e)
        ErrorRecord errorRecord = new ErrorRecord(e, "Error writting to the config file.", ErrorCategory.WriteError, config);

Multiple database support with Entity Framework

One of the features introduced in Entity Framework is being database independent. Which mean each database provider can support Entity Framework by implementing its provider.

This feature allows you build applications independent from the underplaying database provider. In this post I'm going to show how to build an application that support multiple databases using same conceptual model made by Entity Framework.

Using a CompareValidator to check input is a valid date

The CompareValidator can do more than just compare two controls. You can also compare it against several of the main .net data types such as Date, Integer, Double and Currency.

To do this you would set Operator="DataTypeCheck" and instead of setting the ControlToCompare or ValueToCompare attributes as you normally would you use the Type="Date" (or any of the data types I have listed above).

Export Visio Database Table Names to Excel

If you use the Enterprise Architect edition of Microsoft Visio for data modeling regularly, then there is a good chance that at some point you've wanted to export just the table names into Excel. You might want to do this to map logical ERD entities to physical data model tables, track project status by entity, or track overlap between database versions.

MS SQL Server: Disconnect Users From Database - Kill User Session

If you ever wanted to restore your database from a SQL backup file (.bak), but there are still users connected to your database, the backup operation will fail causing the error: Exclusive access could not be obtained because the database is in use.

Publishing SQL Server Database using Publishing Wizard : Tips & Tricks

We can use SQL Server Publishing Wizard to deploy our local Database to remote hosting server/production server.This feature is available in SQL Server 2008/VWD 2008.

Below is the complete step by step guide of this process.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend