I want to save the results of the MVC MiniProfiler to a sql server database. I profile a high load mvc4 page to spot a tricky performance problem which is non-reproducible on our test or development system and only happens sporadically on the production server.
What is the best way to hook into the mini profiler? Is there an existing extension to do that?
I've just been setting up MiniProfiler to save the results to SQL Azure, it's fairly easy. We're using MiniProfiler.MVC3 to take care of all the wiring up as described here.
The table create script is embedded into the assembly with the SqlServerStorage.TableCreationScript static field, so you can use that, but while digging into the code I found the latest development branch has enhanced the script slightly by adding some indexes. The table structure is otherwise unchanged, so it still works with the latest package available on nuget.
At the time of writing here is direct link to the latest table create script.
After that the only thing you need to do is set-up MiniProfiler to use SQL with single line of code:
MiniProfiler.Settings.Storage = new SqlServerStorage("<your connection string>");
If you're not using SQL Azure, that's it, but I found one issue when we tried to use it in Azure. I received the following exception (thank you ELMAH) when profiling tried to save:
System.Data.SqlClient.SqlException
Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.
To solve this I had to add an additional (unused) column to the MiniProfilers table. Here is the beginning of the create table script in question:
create table MiniProfilers
(
RowId integer not null identity constraint PK_MiniProfilers primary key clustered, -- Need a clustered primary key for SQL azure
Id uniqueidentifier not null,
Name nvarchar(200) not null,
And since the Guid Id column was no longer the primary key, I added an additional index to ensure lookups are still fast:
create unique nonclustered index IX_MiniProfilers_Id on MiniProfilers (Id)
Hope that helps.
Update
The change to support SQL Azure has been provided as a Pull Request and accepted. Thanks Jarrod.
Related
I'm trying to integrate my Oracle Database into my ASP.NET app, but I keep getting this error :
Error 2002: The EntityContainer 'OracleDBTargetContainer' for the
storage model specified as part of this MSL does not exist in
MetadataWorkspace.
I've tried everything I could think of but still can't figure out what's wrong.
What can I do to diagnose the root cause of this?
This is still new to me so I might miss something very obvious.
I'm assuming it my not like my database as the Diagram displayed when I integrated another DB. I've checked the foreign keys, primary keys, ... but to no good.
Using VS2013 with ODP.NET 12c Release 3.
EDIT : My EntityContainerMapping is empty, is that normal?
<EntityContainerMapping CdmEntityContainer="PMModelContainer" StorageEntityContainer="PMModelTargetContainer"></EntityContainerMapping>
I found what was wrong.
One of my foreign key didn't match the primary key (Number 20 instead of Number 10)
I saw on stack overflow that it could be a problem and checked my tables but I missed that one obviously.
How did I realize it ? Well because rather than creating the EF Designer, I chose the Code First from database option, and, oh, what do you know, the error message now tells you EXACTLY what the problem is ! (Table names and columns).
My name is Stefano Fanti,I am a developer in Plexa.We are actually using your component ( FireDAC ) and I am contacting you in order to solve some
problems we have not been able to fix ourself.
In our company we decided to port a legacy 3-Tier DATASNAP application written on Delphi7 for the new environment Delphi XE7 , and we decided to use the new components library FireDAC too.
Our application is built in this way: a Client side using TClientDataSet directly connected to the Server side with TDataSetProvider/MIDAS and TTable TQuery TDatabase components (BDE)
We replaced BDE components with the related FireDAC ( FDConnection , FDTable and FDQuery ) without issues and we started testing thinking anyway it was not needed to perform it.
After some test , a couple of issues have arosen : the first problem is related to the modifications performed on DB ( MS SQL Server ) , the second is related the the reopening of the table after applying the modifications.
In our case , the RequestLive=True property ( default ) , does’nt allow to apply modifications ( Post/ApplyUpdates) to the Database.
Assigning RequestLive = False , we are able to apply modifications on all table’s records except the first, the last giving us the error .
The above anomaly have been verified on each Database table . However all database tables have the primary key defined properly.
Trying to use FireDAC Help I read the option RequestLive=False excludes fiMeta from Fetch,Options, preventing the component to use the primary key of the table, being otherwise seen correctly in any other case.
After several trials I found two configurations applied to the Server side, allowing us to achieve the result.
First configuration
FDTable.RequestLive= False
FDTable.UpdateMode = upWhereKeyOnly
with FProvider.DataSet.FieldByName (pkField) do
ProviderFlags: = ProviderFlags + [pfInKey];
Second configuration
FDTable.RequestLive= False
FDTable.UpdateMode = upWhereAll
TDataSetProvider.UpdateMode=upWhereAll
The above configurations give us the possibility to apply modifications to tables without errors , but nevertheless don’t allow us to solve the second problem : reopening of the tables for each operation. Indeed , the BeforeOpen and AfterOpen managers are executed each time.
What can I do to avoid the Table to be needless reopened after each modification ?
Are the configurations used to apply modifications correct , or maybe another solution exist allowing us to avoid code modifications causing us to lengthen development times ?
Thank you in advance for your help.
Best regards
Stefano Fanti
I was using UniDac for a long time now and decided to move on to FireDac as it has good Asynch methods after moving on i saw that none of my data editing works anymore it gives me an error:
[FireDAC][Phys]-330. Cannot generate update query. Update table undefined.
What I am trying to do here is i have a TFDStoredProc component who gets all the data from the database and lets me edit it, with unidac I could easily edit the data without any problem like this:
StoredProc.Edit;
StoredProcCreatedID.Value := SomeValue;
StoredProc.Post;
and it worked, but with AnyDac it doesn't, I tried specifying manually the UpdateTable which leads to another problem:
[FireDAC][Phys][ODBC][Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid column name 'CreatedID'.
I am using Microsoft SQL Server 2012 FireDac 8.0 and stored procedures for getting back results any ideas?
P.S.
The query looks like this
SELECT
CreatedBy as CreatedID,
usr.UserName as CreatedBy
FROM
Sales
LEFT JOIN
Users usr ON usr.ID = Sales.CreatedBy
it looks like the FireDac update builder doesn't recognize the aliases on the fields, any help would be appreciated.
Well i figured out what was the issue, it seems that if you specify a alias in the query for a field the Origin property will be set to the alias and not the real field i downloaded CNPack a must have for a delphi developer also its free, ran the component selector and changed all my aliased fields to their real fields and it works, but this is still a big issue in FireDac component because it doesnt recognize the aliased fields, lets hope it will be fixed in the future as to specify for every query what table it should update and what fields that just allot of work if you are migrating from a big project in my case 220+ stored procedures.
I'm using a TClientDataSet as a local dataset without the provider concept. After working with it a method is called that should generate the corresponding SQL statements using the StatusFilter to resolve the changes (generate SQL basically).
This looked easy initially after reading documentation (set StatusFilter to [dsInsert], process all inserts SQL, set StatusFilter to [dsModified] process all updates, the same with deletes) but after a few tests now looks far from trivial, for example:
If I add a record, then edit it: setting the StatusFilter to [dsInserted] displays it, but with the original data.
If I add a record, then edit, then delete it: the record appears with StatusFilter set to [dsInserted] and [dsModified] also.
And other similar situations..
1) I know that if first I process all inserts, then all updates then all deletes the database will be updated in the correct state but it looks far from right this approach (generating useless sql statements).
2) I've tried to access the PRecInfo(ClientDataSet.ActiveBuffer + ClientDataSet.RecordSize).Attribute information (dsRecNew, dsRecOrg, etc.) but still not manage to resolve the logic.
3) I can program the logic to resolve it, for example before processing and insert, set StatusFilter to [dsDeleted], and locating by the primary key if the record to see if its deleted thereafter.. the same with edits, before inserting, checking if the record was updated after so the insert sql in the updated version and so on.. but it should be more easy..
¿Did someone tried to solve this in an elegant and straightforward way? ¿I'm missing something? Thanks
I'm using Firebird 2.5.0 with the Entity Framework, which has been working well. However, recently I have changed something (I presume) and now the SQL that is being generated when I try to save my changes is not valid for Firebird:
update ( select [fields] from [table]) set [field] = #p0 where ([keyfieldn = #pn])
As far as I know, Firebird 2.5.0 does not support this syntax, and when I try to save changes I get back a SQL error that says as much ( "Token unknown, column 8: (" )
I'm not sure what to do now. What would cause the UpdateTranslator instance to generate this SQL instead of whatever it must have been generating before I broke it?
I went back through the edmx file and found that I had gotten some 'DefiningQuery' elements when I had it pull in some new fields from the database. I couldn't find any way to access those settings in the interface, so I just deleted them from the file and it is working correctly again.