SQLite with WebMatrix.WebData.SimpleMembershipProvider Long to Int Cast Error - asp.net-membership

I'm trying to use the SimpleMembershipProvider with SQLite to enable authentication on my site. I have it initialized in my Global.aspx and can create users, however I can't log users in. I get the following error when I try to call WebSecurity.Login([UserName], [Password]):
Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?)
The stack trace is as follows (after I make the call to the Login function:
CallSite.Target(Closure , CallSite , Object ) +146
System.Dynamic.UpdateDelegates.UpdateAndExecute1(CallSite site, T0 arg0) +661
WebMatrix.WebData.SimpleMembershipProvider.VerifyUserNameHasConfirmedAccount(IDatabase db, String username, Boolean throwException) +315
WebMatrix.WebData.SimpleMembershipProvider.ValidateUser(String username, String password) +162
WebMatrix.WebData.WebSecurity.Login(String userName, String password, Boolean persistCookie) +32
I know that SQLite only allows Int64 values in numeric columns (that aren't float). The question is: how do I get the SimpleMembershipProvider to work with Int64 values? I had a look at the source code for the offending routines listed in the stack trace and it seems that all numbers are being explicitly cast before being returned from their Int32 functions. However, I don't have the source to System.Dynamic.UpdateDelegates.UpdateAndExecute1 or CallSite.Target, so I can't see what is going on there. What is more, those are probably pre-compiled. So, the question remains, how can I get this to work?

The SimpleMembership Provider only supports SQL Server and SQL Compact 4.0. SQLite is not supported. If you want to use SQLite, you will have to create your own implementation of ExtendedMembershipProvider. You can more or less copy SimpleMembershipProvider.cs, and just modify the bits where the data type conflict arises.

Related

how do i convert a timespan to a string in visual studio

It gives an error,
Exception Details: System.InvalidCastException: Conversion from type 'TimeSpan' to type 'String' is not valid.
Time.Text = datareader1.GetValue(3)
I'm trying to display the data from the database(MS ACCESS), the data display is a time type.
Just call ToString():
Time.Text = datareader1.GetValue(3).ToString()
The fact that you're currently seeing this at execution time suggests that you've got Option Strict set off. (I'm assuming this is VB.) I would suggest having Option Strict on unless you really, really need it off for deliberate late-binding reasons.

EF using Oracle (ODP.NET) works on one machine, throwing exceptions on another

Everything works fine on my development box (Windows 7 64 bit), I am able to retrieve records and save records.
When I deploy out to a Windows Server 2008 (32 bit) machine, I am able to retrieve data and view it fine. The problem comes when I either:
1) Try to save:
System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.ArgumentException: The specified value is not an instance of type 'Edm.Decimal'
Parameter name: value
at System.Data.Common.CommandTrees.ExpressionBuilder.Internal.ArgumentValidation.ValidateConstant(TypeUsage constantType, Object value)
at System.Data.Mapping.Update.Internal.UpdateCompiler.GenerateValueExpression(EdmProperty property, PropagatorResult value)
at System.Data.Mapping.Update.Internal.UpdateCompiler.BuildPredicate(DbExpressionBinding target, PropagatorResult referenceRow, PropagatorResult current, TableChangeProcessor processor, Boolean& rowMustBeTouched)
at System.Data.Mapping.Update.Internal.UpdateCompiler.BuildUpdateCommand(PropagatorResult oldRow, PropagatorResult newRow, TableChangeProcessor processor)
at System.Data.Mapping.Update.Internal.TableChangeProcessor.CompileCommands(ChangeNode changeNode, UpdateCompiler compiler)
--- End of inner exception stack trace ---
at System.Data.Mapping.Update.Internal.TableChangeProcessor.CompileCommands(ChangeNode changeNode, UpdateCompiler compiler)
at System.Data.Mapping.Update.Internal.UpdateTranslator.<ProduceDynamicCommands>d__0.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
at System.Data.Mapping.Update.Internal.UpdateCommandOrderer..ctor(IEnumerable`1 commands, UpdateTranslator translator)
at System.Data.Mapping.Update.Internal.UpdateTranslator.ProduceCommands()
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Entity.Internal.InternalContext.SaveChanges()
--- End of inner exception stack trace ---
at System.Data.Entity.Internal.InternalContext.SaveChanges()
at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
at System.Data.Entity.DbContext.SaveChanges()
at Dashboard.Data.Repository.RepositoryBase`2.OnCompleteSave()
2) Or try to retrieve the next number in a sequence:
System.InvalidOperationException: The specified cast from a materialized 'System.Decimal' type to the 'System.Int64' type is not valid.
at System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
at lambda_method(Closure , Shaper )
at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Dashboard.Data.DashboardDbContext.ExecuteScalar[TResult](String query, Object[] parameters) in c:\Builds\1\Exploration Archives\Dashboard (MAIN) (talus test)\Sources\Exploration Archives\Dashboard\Main\Dashboard.Data\Dashboard.contrib.cs:line 23
at Dashboard.Data.Repository.RepositoryBase`2.GetNextIdFromSequence()
The part that confuses me the most is the fact that after being deployed to the Windows Server 2008 machine, things partially work (I am able to retrieve data), but it only breaks when I try to retrieve from a sequence or save.
Any ideas what could be causing this?
Found the issue.
For my ID columns, on my .NET objects I was using data type long, with the corresponding oracle data type number. Worked fine on my machine. Based on other research into this issue, I tried changing the oracle data type to number(19). Still no go.
Seems like long support is flaky at best. I had to change my .NET objects' data types to int, and changed the oracle data types to int as well. This worked.
The part that bothers me most is that it obviously saw number and number(19) as a decimal data type, and it had no problem doing a narrowing conversion for me to long. The issue only came up when I tried to save, doing a non-narrowing conversion long to decimal. Go figure.
Adding a comment here for future reference as this issue also effects the Mysql Drivers - EntityFramework v6 and MySql.Data.Entities.6.8.3.0. Unsigned bigint db columns cause this issue.
"id BIGINT(20) UNSIGNED" causes a "The specified value is not an instance of a valid constant type. Parameter name: type" exception. Changing the associated class property ulong does not help. Binding db column "id BIGINT(20)" to...
[Key]
[Column("id")]
public long Id { get; set; }
...works fine.

ASPxGridView page works for some users, not for others. WebForm model using C#, ASP, SQL Express

I am debugging a website built on the WebForms model, using ASP, C# as codebehind, and SQL Express 2008 R2. I am trying to debug a page that uses an ASPxGridView, which is populated from the .aspx file, and the dataset is uses is created there as well. The data is selected using
SelectCommand="SELECT MachineID, ProgramNo, (CONVERT (VARCHAR(19), Start, 120)) as Start,(CONVERT (VARCHAR(12), Stop,114)) as StopTime, WorkCount, PartCount as TotalWorkCount,(CONVERT (VARCHAR(12), Stop-start,114)) as PartCycle FROM Program WHERE (MachineID = #MachineID) AND (WorkCount > 0) AND (CONVERT (VARCHAR(19), Start, 120) >= #StartDate) AND (CONVERT (VARCHAR(10), Start, 120) <= #EndDate) order by Start Desc">
The problem is that most users can login and the page works perfectly, but a few users see the following error in the web browser:
A field or property with name 'PartCycle' was not found in the selected data source. Possible causes of this error may be the following: an incorrect or case-insensitive spelling of the grid column name; assigning a wrong or not properly initialized data source to the grid.
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.Web.HttpException: A field or property with name 'PartCycle' was not found in the selected data source. Possible causes of this error may be the following: an incorrect or case-insensitive spelling of the grid column name; assigning a wrong or not properly initialized data source to the grid.
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:
[HttpException (0x80004005): A field or property with name 'PartCycle' was not found in the selected data source. Possible causes of this error may be the following: an incorrect or case-insensitive spelling of the grid column name; assigning a wrong or not properly initialized data source to the grid.]
DevExpress.Web.Data.WebDataControllerProvider.GetRowValueByControllerRow(Int32 controllerRow, String fieldName, Boolean isDesignTime) +300
DevExpress.Web.Data.WebDataControllerProvider.GetRowValue(Int32 visibleIndex, String fieldName, Boolean isDesignTime) +203
DevExpress.Web.Data.WebDataProxy.GetRowValue(Int32 visibleIndex, String fieldName) +77
As you can see, PartCycle is not a column in the tables, but is used as an alias for (CONVERT (VARCHAR(12), Stop-start,114)). To put a twist in the plot, I can view the problem data just fine when I am logged into the site as an Administrator. The users who see this error have various ASPNET Roles, but each have access to the data in the tables selected.
Its because ASPxGridView Caches the Columns.
In your case, your datasource is dynamic i.e. different for different users.
Make sure to Clear the Columns before binding ASPxGridView.
To Clear the Columns:
agvObject.Columns.Clear();

CA2135 and CA2122 battle

I have a class that hits an Active Directory. It does looks up a user on the domain and checks their grouping. Here is my function definition:
[DirectoryServicesPermission(SecurityAction.LinkDemand, Unrestricted = true)]
public bool IsUserMemberOfGroup(String userName, String groupName)
I get error CA2135. So I change it to use Security critical as it states in the MSDN page:
[SecurityCritical]
public bool IsUserMemberOfGroup(String userName, String groupName)
Now, I get error CA2122, which asks me to change it back to using LinkDemand. Short of supressing this error, is there anything I could do?
I strongly suspect that the CA2122 rule has not been fully updated to work with level 2 transparency. While it recognizes a SecurityCritical assembly-level attribute, it ignores a SecurityCritical type- or member-level attribute in an APTCA assembly. It's probably safe to add the SecurityCritical attribute and suppress the CA2122 violation, but you might also want to verify that code that lacks unrestricted DirectoryServicesPermission can't actually call into your method.

How do I create an instance of Oracle.DataAccess.Client.OracleException to use with NMock

I'm using the Oracle.DataAccess.Client data provider client. I am having trouble constructing a new instance of an OracleException object, but it keeps telling me that there are no public constructors. I saw other having the same problem and tried their solutions, but they don't seem to work. Here's my test code:
object[] args = { 1, "Test Message" };
ConstructorInfo ci = typeof(OracleException).GetConstructor(BindingFlags.NonPublic
| BindingFlags.Instance, null, System.Type.GetTypeArray(args), null);
var e = (OracleException)ci.Invoke(args);
When debugging the test code, I always get a NULL value for 'ci'.
Has Oracle changed the library to not allow this? What am I doing wrong and what do I need to do to instantiate an OracleException object to use with NMock?
By the way, I'm using the Client library for version 10g.
Thanks,
Charlie
OracleException in ODP.NET not the same as OracleException in Microsoft client.
OracleException have 5 constructors information of which you can obtain by GetConstructors().
In the obtained list of the constructors you will see that there are no constructor with parameters (int, string). That why you getting NULL in ci.
If you give a proper list of the parameters you will have proper ConstructorInfo and will be able to call a constructor by Invoke(param);
However, OracleException constructor not designed to be called like this - not all the fields will have a proper information.
2All:
I need following OracleException:
ORA-00001 unique constraint (string.string) violated
ORA-03113 end-of-file on communication channel
ORA-03135: connection lost contact
ORA-12170: TNS: Connect timeout occurred
for testing. How do I create them?

Resources