error in running transformation:indexoutofrangeexception - petapeco - asp.net-mvc

as per suggestion for by #CreativeManix I started investigating petaPeco
Retrieving large number of rows (more than 10 mil) in asp.net mvc application
After adding exact system.data.oracleclient + putting web.config in the bin where mvc is getting compiled in .dll I got following error:
Error 3
Running transformation: System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Array.InternalGetReference(Void* elemRef, Int32 rank, Int32* pIndices)
at System.Array.GetValue(Int32 index)
at Microsoft.VisualStudio.TextTemplating5F4490FB7AE018243DBB4DF6250E7211.GeneratedTextTransformation.GetCurrentProject()
at Microsoft.VisualStudio.TextTemplating5F4490FB7AE018243DBB4DF6250E7211.GeneratedTextTransformation.GetConnectionString(String& connectionStringName, String& providerName)
at Microsoft.VisualStudio.TextTemplating5F4490FB7AE018243DBB4DF6250E7211.GeneratedTextTransformation.InitConnectionString()
at Microsoft.VisualStudio.TextTemplating5F4490FB7AE018243DBB4DF6250E7211.GeneratedTextTransformation.LoadTables()
at Microsoft.VisualStudio.TextTemplating5F4490FB7AE018243DBB4DF6250E7211.GeneratedTextTransformation.TransformText()
at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result)
This error shows up when i run the transformation after installation of petaPoco.
One thing I do know the error is coming from "GetCurrentProject" - and probably - "(Array)dte.ActiveSolutionProjects"
I think something is wrong in the way petaPoco is set up with my project! somehow it can't find the activesolution project. I am not too sure how to fix it.

I investigated this.
In my question section I asked few questions:
I was not sure about how to fire transformation/or process of generating Database.CS. So initially I was installing petapoco from the command prompt- I
To do that you just click "Run Custom Tool" by right clicking on the "Database.tt". If your connection string is correct + you are referencing correct Oracle/SQL server data provider + that provider is available in GAC + (if it is oracle and you have the password for the default schema user of the database you are trying to access)- then that should generate the Database.cs
To enable Oracle data client to read the schema out of oracle database I needed to take out following entry:
cmd.GetType().GetProperty("BindByName").SetValue(cmd, true, null);
And everything worked.
Connection string can look like:
connectionString="Data Source=PXWREG;Persist Security Info=True;User ID=XWREG_ACDS_T;password=isacdst"

Related

Troubleshoot the SqlProgrammabilityProvider

I can't seem to get the SqlProgrammabilityProvider to work even in the most basic configuration. With this code
type TestDb = SqlProgrammabilityProvider<testConn>
let db = TestDb()
I get the design/compile-time error "The value or constructor 'TestDb' is not defined"
testConn is a literal string that is working fine with the SqlCommandProvider in the same project.
I'm using VS 2015, FSharp.Data.SqlClient 1.7.5, and I've tried targeting .NET 4.5.2 and 4.6.
Are there known issues or limitations with this? If not, how could I troubleshoot it?
After getting a type for SqlProgrammabilityProvider upon a specific connection you should tie it to as many as you like, but of the concrete following options: Sql Server function, stored procedure, or table.
Like in:
type TestDb = SqlProgrammabilityProvider<testConn>
type Datatable = TestDb.dbo.Tables.MyDataTable
or
use cmd = TestDB.dbo.MyStoredProcedure()
cmd.Execute(Param1="xyzzy")
You may peek at use cases at https://github.com/fsprojects/FSharp.Data.SqlClient/tree/master/src/SqlClient.Tests

TFS Database Backup Failed : There is an error in XML document - but which Doc?

Our Nightly TFS 2012 backup has just started to fail. It also fails when run directly through TFS Express Administration Console.
Which file is the following error actually referring to? If I can find it then I should be able to fix the "Root element is missing" error :)
[13/08/2014 23:00:00] [Info] Full database backup job
[13/08/2014 23:00:00] [Info] Getting backup lock
[13/08/2014 23:00:05] [Error]
Exception Message: There is an error in XML document (0, 0). (type InvalidOperationException)
Exception Stack Trace: at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at Microsoft.TeamFoundation.Admin.BackupSets.Load(String folder)
at Microsoft.TeamFoundation.Admin.Jobs.FullDatabaseBackupJobExtension.Run(TeamFoundationRequestContext requestContext, TeamFoundationJobDefinition jobDefinition, DateTime jobQueueTime, String& resultMessage)
Inner Exception Details:
Exception Message: Root element is missing. (type XmlException)
Exception Stack Trace: at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res)
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlReader.MoveToContent()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderBackupSets.Read7_BackupSets()
[13/08/2014 23:00:05] [Info] Full Backups Failed
Thanks.
Dylan answered my original question as to where to find the unspecified xml file that was in error, but in case it helps anyone else...
The Backupsets.xml file was empty. Why this is I do not know...
Attempting to configure backups through TFS Express Administration Console also failed with the same error, so I
Deleted the Backupsets.xml file altogether
Reconfigured Backups using the wizard - Now that it didn't find the xml file at all it created a new one.
Ran a full backup - which was sucessful. Hopefully the scheduled backups will now also work from now on.
NB The newly created Backupsets.xml file (Before the first full backup) :
<?xml version="1.0"?>
<BackupSets xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Version>1</Version>
<BackupSets />
</BackupSets>
Look in the folder where your backups are configured to be placed. there will be an XML file there, can't remember the name, but maybe something like BackupSets.xml
FIX (user workaround):
Rename the file BackupSets.xml in the backup destination folder
Re-run Full Backup*
In TFS Admin Console select Scheduled Backups, then click Take Full Backup Now. Or use command line, PowerShell script, API call as desired.
CAUSE: backupsets.xml in backup destination does not contain valid XML.
Why does this cause failure? Backup wizard opens backupsettings.xml then calls XML deserializer function System.Xml.Serialization.XmlSerializer.Deserialize preparing to add new entry. Invalid XML content including empty/zero byte or text-only content will cause deserialize exception.
PRODUCTS IMPACTED: Repro confirmed in TFS2010 and on 2017-11-25 I had repro with TFS2015 SP3 :-O
Fix is fairly straightforward... once you understand what is going on. -Zephan
MICROSOFT CODE BUGFIX/feature improvement request:
BACKUP Wizard exception handling for backupsets.xml deserialize or parsing exceptions.
If XML deserialization error then close backupsets.xml, rename it to backupsets-YYMMDD-hhmm-corrupt-backup.xml, then jump to backupsets.xml file not found functionality.
SEVERITY: HIGH (data loss)
This is a long-standing problem that can lead to major data loss. I've personally seen over 1 month of data loss due to this issue silently blocking backups and making all earlier restore sets unusable (since parsing BackupSets.xml is VERY finicky I couldn't even hack to restore last successful backup.)

dotnetopenauth samples "Attempt by method 'DotNetOpenAuth.OAuth2.WebServerClient ..."

I've just been spending hours on an issue that some others have reported to experience too.
The Sample.Oauth2.OAuthClient projet sample does not work for me.
Let me explain in details:
I got the latest version of dotnetopenauth from github (december 12th)
I ensured to "unblock" the zip before extracting all files.
I opened the solution with VS2012 (under Win7)
When starting the
Sample.Oauth2.OAuthClient project,
the overall build process succeed.
The website is started.
When calling
Sign in with Facebook (OAuth 2.0)
I get
Attempt by method
'DotNetOpenAuth.OAuth2.WebServerClient+d__3.MoveNext()'
to access method
'System.Collections.Generic.List`1..ctor()' failed.
Line 106: // verifiable for the same user/session.
Line 107: // If the host is implementing the authorization tracker
though, they're handling this protection themselves.
Line 108: var cookies = new List();
Line 109: if (this.AuthorizationTracker
== null) {
Line 110: string xsrfKey =
MessagingUtilities.GetNonCryptoRandomDataAsBase64(16, useWeb64: true);
That the provided code is not able to access "System.Collections.Generic.List" bewilders me...
I tried the following :
adding
<system.web>
<securityPolicy>
<trustLevel name="Full" policyFile="internal"/>
</securityPolicy>
to web.config.
Note that checking just before the line the "CurrentTrustLevel" results in "Unrestricted".
I tried to publish to local IIS 7,
tried running the pool under "administrator"
and finally
I tried with VS2013 on another, "clean" installation of Win7,
All attempts lead to the same result ...
It seems that the errors comes from some System.Net Dlls provided with the samples : they cannot be run by asp.net for security reasons (?)
Any idea ?

Activation error occured while trying to get instance of type LogWriter, key ""

I am getting this error while loggin into eventviewer. I am looging the exception in event viewer as well as rolling flat file. If i remove the eventviewer section then rolling flat file works perfectly, but only when i add this it gives the exception
{"Resolution of the dependency failed, type =
\"Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter\", name =
\"(none)\".\r\nException occurred while: while resolving.\r\nException
is: InvalidOperationException - The type TraceListener cannot be
constructed. You must configure the container to supply this
value.\r\n-----------------------------------------------\r\nAt the
time of the exception, the container was:\r\n\r\n Resolving
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl,LogWriter.default
(mapped from Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,
(none))\r\n Resolving parameter \"structureHolder\" of constructor
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder
structureHolder,
Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProvider
instrumentationProvider,
Microsoft.Practices.EnterpriseLibrary.Logging.ILoggingUpdateCoordinator
updateCoordinator)\r\n Resolving
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder,LogWriterStructureHolder.default
(mapped from
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder,
(none))\r\n Resolving parameter \"traceSources\" of constructor
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder(System.Collections.Generic.IEnumerable1[[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35]] filters,
System.Collections.Generic.IEnumerable1[[System.String, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
traceSourceNames,
System.Collections.Generic.IEnumerable1[[Microsoft.Practices.EnterpriseLibrary.Logging.LogSource,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35]] traceSources,
Microsoft.Practices.EnterpriseLibrary.Logging.LogSource
allEventsTraceSource,
Microsoft.Practices.EnterpriseLibrary.Logging.LogSource
notProcessedTraceSource,
Microsoft.Practices.EnterpriseLibrary.Logging.LogSource
errorsTraceSource, System.String defaultCategory, System.Boolean
tracingEnabled, System.Boolean logWarningsWhenNoCategoriesMatch,
System.Boolean revertImpersonation)\r\n Resolving
Microsoft.Practices.EnterpriseLibrary.Logging.LogSource,General\r\n
Resolving parameter \"traceListeners\" of constructor
Microsoft.Practices.EnterpriseLibrary.Logging.LogSource(System.String
name,
System.Collections.Generic.IEnumerable1[[System.Diagnostics.TraceListener,
System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]] traceListeners,
System.Diagnostics.SourceLevels level, System.Boolean autoFlush,
Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProvider
instrumentationProvider)\r\n Resolving
System.Diagnostics.TraceListener,Event Log Trace Listener\r\n"}
I had the same problem and it was due to an error in my configuration file. I referenced trace listeners from my categorySources section which did not exist in my listeners section. I removed the categories and the mappings (i did not use them anyway) and then it worked. I guess you can validate your configuration file in the configuration console and then it will tell you what the problem is.
1 - Make sure you are referencing the correct DLLs
Microsoft.Practices.EnterpriseLibrary.Logging
Microsoft.Practices.EnterpriseLibrary.Common
2 - Make sure your configuration file is in the right location (in the same project or in a references project)
3 - Make sure your configuration file is correct. Editing it with the Enterprise Library Configuration Tool, nothing should be in red. Try expanding all trace listeners, categories, etc. The most common error is that one of the Special Categories is pointing to a non existing Listener.
I had a similar experience with ExceptionHanlder., I switched over to using Unity container directly after playing around with intro material re: logging.
I basically just copied the examples from the Help files and briefly wondered why it wasn't working and errored on Type Resolution; Could not resolve.
The answer was simple enough. I had only "played" with logging prior to switching to Unity container but the examples I was using/copying were using both Logging and Exception Handling injection.
Since I hadn't "played: with Exception Handling in 5.0, there were no entries for this in the configuration file, hence the reason why Unity could not resolve.
Solution: take 5 seconds to add the ExceptionHandling block into the config file using the tools and I was good to go and keep on "playing".
Unity needs the entries for each resolved block in the config file even if they are not Named / customised. This is rediculously obvious but easily overlloked if you are hacking away with example code for learning purposes.
I got this error because a database listener was set with a connection string that didn't exist.
To help diagnose, comment out the listener lines and then add them again one by one.
I got this error when moving the app to another server, and in my case, it was the initializeData field, which sets the path for the log file, was not valid, and it was not able to create the log file at startup.
When i edited and put a valid path for the log to be created, it worked ok.
Hope it helps someone.

Why is EF4 trying to re-create my database even though the model hasn't changed?

I have an ASP.NET MVC 3 Beta website using SQL Server CE 4.0. With both ScottGu's NerdDinner example and my own code, I will sometimes get the following exception as soon as I try to access the database:
File already exists. Try using a different database name.
[ File name = D:\Sourcecode\NerdDinner\NerdDinner\App_Data\NerdDinners.sdf ]
Line 17: public ActionResult Index()
Line 18: {
Line 19: var dinners = from d in nerdDinners.Dinners
Line 20: where d.EventDate > DateTime.Now
Line 21: select d;
[SqlCeException (0x80004005): File already exists. Try using a different database name. [ File name = D:\Sourcecode\NerdDinner\NerdDinner\App_Data\NerdDinners.sdf ]]
System.Data.SqlServerCe.SqlCeEngine.ProcessResults(IntPtr pError, Int32 hr) +92
System.Data.SqlServerCe.SqlCeEngine.CreateDatabase() +1584
System.Data.SqlServerCe.SqlCeProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 timeOut, StoreItemCollection storeItemCollection) +287
System.Data.Objects.ObjectContext.CreateDatabase() +84
System.Data.Entity.Internal.DatabaseOperations.Create(ObjectContext objectContext) +35
System.Data.Entity.Infrastructure.Database.Create() +70
System.Data.Entity.Infrastructure.CreateDatabaseOnlyIfNotExists`1.InitializeDatabase(TContext context) +360
System.Data.Entity.Infrastructure.Database.Initialize() +272
System.Data.Entity.Internal.InternalContext.Initialize() +90
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +34
System.Data.Entity.Internal.Linq.EfInternalQuery`1.Initialize() +140
System.Data.Entity.Internal.Linq.EfInternalQuery`1.get_Provider() +29
System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +34
System.Linq.Queryable.Where(IQueryable`1 source, Expression`1 predicate) +63
NerdDinner.Controllers.HomeController.Index() in D:\Sourcecode\NerdDinner\NerdDinner\Controllers\HomeController.cs:19
I cannot figure out why this works sometimes with an existing .dbf file and other times it complains. I have even tried explicitly setting the default behaviour with
Database.SetInitializer(new CreateDatabaseOnlyIfNotExists<...>());
Has anyone else experienced this?
Restarting Cassini doesn't seem to make a difference.
Hitting refresh in IE after receiving this error will make the exact same page load properly.
Sorry to resurrect such an old question, but I was experiencing this today and have found a workaround which does not involve installing an older version of the CTP.
From The correct url for the blogpost is http://www.hanselman.com/blog/PDC10BuildingABlogWithMicrosoftUnnamedPackageOfWebLove.aspx (about half-way through the blog post)
*Go into your AppStart_SQLCEEntityFramework.cs file and the DefaultConnectionFactory line to this:*
Database.DefaultConnectionFactory = new SqlCeConnectionFactory(
"System.Data.SqlServerCe.4.0",
HostingEnvironment.MapPath("~/App_Data/"),"");
My particular database is placed in the App_Data folder but I'm assuming that if yours is not you should be able to change the path to suit and it will work.
Hope this helps!
It looks like this is a recently discovered bug.
MSDN Forum
The workaround is to re-install SQL Server CE 4.0 CTP 1 download
Install and use SQL Server CE CTP1, which is still downloadable on Microsoft sites. This solved my problem with that.
I had the same problem today with released MVC3 and SQL Server CE 4.0 downloaded with NuGet and it was resolved by uncommenting the line:
DbDatabase.SetInitializer(new CreateCeDatabaseIfNotExists<MyContext>());
And replacing MyContext with the context class that was inheriting from DBContext in the models folder.
The final SQL Compact Edition 4.0 is out and after installing it the issue is not happening anymore. Here is the announcement from the team blog:
Microsoft SQL Server Compact 4.0 is available for download

Resources