I have a website and a web application that both log to a common error table. I want to be able to know which project logged the error. But I cant do it with some global property. I would like to get the project name through reflection. Is this possible? Is it even kept in the manifest and will be be available no matter what symbols the projects have been built with?
Try with below
System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location)
Ref Link::: Get executing assembly name using reflection
http://forums.devshed.com/net-development-87/c--get-project-s-name-via-net-object-483704.html
"Project" is purely a VS/MSBuild concept and as such does not exist outside of realm of these tools. What I can suggest instead is to use first "segment" of a namespace of Global.asax-"derived" application.
var applicationName = typeof(Application).Namespace.SubstringBeforeFirst(".");
i see two solutions (assuming your error table is SQL-based)
dupe error table and "give" eachproject its own to write into, then if you need to aggregate them you can make up a simple union in a view (you can then have project name in the resulting table based on where the records come from)
add a column "project name" to the error table, then fill it when you write your error (since every project knows what's his name when it writes, it's a trivial task and hardcoding this data wouldn't smell too much)
if you have restricitons, please explain what where and why so we can help more easily.
Related
I want to re-code my existing project (WPF Code-Behind) in MVVM and want to make much better.
In the old project i saved all (including MySQL Connection Info) in App.config.
But I read that this is much unsecure and not recommended. So I want to ask you, whats the best and securest way for MVVM to save and read config.
In the Config I want to store following for example:
bool StayLoggedIn (When Checkbox at login is checked this should be true to stayloggedin, this can be unsecure)
string Mysql_DATABASE (the database)
string Mysql SERVER (the server)
string Mysql User (user)
string Mysql Password (password)
As you can see, people shouldnt see this config file. But the program should be able to read and write this file.
I can't use App.config too because I created 2 Projects in my Solution. 1 for my Views called Ui.Desktop and 1 for my ViewModels called Logic.Ui.
So Logic.Ui doesn't have App.config and I cant get access of the App.Config then. So there have to be another way.
You can still use the application configuration file with an encrypted connection string (or whatever other values you need). If the "Ui.Desktop" project is the solution startup project, that is the one that must have the app.config with the data in it. That is assuming of course that the "Logic.Ui" project is a reference.
I believe the better question to ask yourself is where are you placing your configuration elements? If you are building them in your "Logic.Ui" projection that would not be the correct project to do so. It is called "Separation of Concerns".
A better way of creating this solution might be to create a project that is concerned with starting your application, reading any configuration, and running whatever it is you want to run. If this is a WPF application place all of your views in a folder called "Views". If your "Logic.Ui" project has the ViewModel's then you can reference this project and use the classes you build in the "Logic.Ui" project. Let me know if this is unclear.
I know this question was already asked but it seams that my case might be slightly different. I tried the "run custom tool" but here's where the strange thing happens: Because i'm having 2 related databases (so 2 related models). If i'm running the custom tool on one model it screws up the other and vice-versa(incomplete .cs files, missing, etc.). Does anyone have any ideea where i'm going wrong?
EDIT:
the complete error:
An exception of type 'System.Data.Entity.Core.MetadataException'
occurred in EntityFramework.dll but was not handled in user code
Additional information: Schema specified is not valid. Errors:
The relationship
'ProductionMasterDataEntityModel.FK_ProductGroup_CostPeriods' was not
loaded because the type 'ProductionMasterDataEntityModel.ProductGroup'
is not available.
The following information may be useful in resolving the previous
error:
The required property 'CstAveOrderQty' does not exist on the type
'SISCOM.Persistance.Models.ProductGroup'.
The custom tool is: TextTemplatingFileGenerator
I'm not sure if it has anything to do with the asp.net framework but it is an asp.net project so i thought it's worth mentioning.
in my case, this Issue came after I update .edmx file. Remove all the tables on it and re-update it.right click on .tt file(Eg. Entity.tt) file->Run custom tools. then my issue solved.
I solve this case like below.
Entity in class lib project and i was try to consume in other project.
So in that project i have add reference "EntityFramework.SqlServer.dll" in new project.
Drop the model from edmx and add it again should sort it out. Note this cannot be reverted unless using source control tools.
It seams that i had 2 problems contributing to that error.. First, there were some stored procedures and views, after i got that out of the way (deleted my models, created them again and i've unchecked the option to include the stored procedures and i only added the tables to the model, no views and no stored procedures) i could access some data but not all of it.. The second problem was that i forgot to add a connection to the dependent database.
So the methods in my repository look like this:
public myType GetSomething()
{
var db = new model();
var dependencyDb = new dependencyModel();
//do whatever needs to be done with the data before presenting it
return something;
}
P.S... i didn't had to explicitly take it to the needed table, after i added the connection it found all that it needed by itself.
Hope this helps anyone having this problem.
I'm a little behind the times on data access and need to be pointed in the right direction. I currently have just a single SQL Server db table with about 35 columns in it. I'm building a WCF web service to provide access to it and am trying to figure out the quickest way to link up the C# based web service to the database.
I've been looking at Entity Framework but it seems pretty heavy and everything I've found on it so far seems to assume you already know something about it so I didn't want to get too far into it if it's the wrong path. I'm not fully sold on the idea of generating SQL in the application. I already have a DataContract class with properties for each column in the table, I'm just looking for an automatic way to map columns to properties and properties back to columns/sproc parameters. I already wrote some code that uses reflection to map data from a different source to this DataContract (matching on property name with a dictionary of additional mappings as a backup) so it's not that much work to do the same here, but I wanted to see what else is available. What I want to avoid is writing out each PropertyName = ColumnName.Value. Is there something light weight built into VS2010 .NET 4.0 for a simple case like this? Would directly calling a stored procedure through EF as is mentioned here be a good option? It looks a little out of date.
I like Dapper, a "micro-ORM". It's used by SO. I've used it beautifully as "an automatic way to map columns to properties" and it appears to also do "properties back to columns/sproc parameters" but I haven't used it for that. It's superb - I had it going in about 5 minutes after getting it with Nuget. I'm a newbie to EF and wouldn't recommend it without a guide.
IEnumerable<TModel> result;
using (MySqlConnection conn = new MySqlConnection(_mysqlConnString))
{
// "Query" is a Dapper extension method that stuffs the datareader into objects based on the column names
result = conn.Query<TModel>("Select * from YourTable");
}
// do stuff with result
This links to a full example, instead of just the piece I pulled out of my current project. http://www.tritac.com/bp-24-dapper-net-by-example
other Dapper information: c-sharpcorner.com/UploadFile/4d9083/… and liangwu.wordpress.com/2012/08/16/dapper-net-samples talk about it.
(moved from comment as this was more an answer than a comment - I'm trying to do the proper task in the proper place).
I have urgent and unexplainable problem so any help would be appreciated. I haave 2 different databases which are exactly the same except there is different data in each of them.
I have a web application using LINQ-To-EF and until I've changed the database in connection string everything was working fine. Even though the databases are exactly the same I receive the error: "Invalid column name 'tema_id'." The problem is that "tema_id" doesn't exist in any of those two databases, however, somehow it does exist in .edmx file. The name of the mapping should be "aktivnost_id" and not "tema_id" how it is now.
I've tried updating the model from the database, but in that case everything gets wrong and I get dozens of different errors in Error List.
I've provided the screenshot of mapping details for the problematic table (you can see "tema_id" which should be "aktivnost_id").
I know my explanation might be a bit confusing, but if any additional info is needed I will provide it.
It I hard to give a complete answer without the full details of the errors that occur when you try to update; however, I would be sorely tempted to edit the EDMX as XML, use "find" to locate tema_id, and fix directly.
If nothing else, it is quick to try :)
Have you tried to edit the .EDMX file directly to match the actual table structure?
Try to generate whole data access layer manually outside of visual studio through edmgen.exe
use the following command for EF4 (adjust parameters to reflect your db name, username, password)
#"%windir%\Microsoft.NET\Framework\v4.0.30319\edmgen.exe" /mode:fullgeneration /c:"Data Source=tcp:127.0.0.1;Initial Catalog=your_database;User ID=sa;Password=your_password;Integrated Security=False;" /project:DataContext /entitycontainer:DataContext /namespace:Project /language:CSharp /pluralize
I have extensive experience working in ASP.NET and Sql Server but I am new to Linq. I have just inherited a project that was created using Linq.
Unfortunately the last developer knew nothing of efficiency and was storing images in the database in a truly terrible way. I have modified the code so that it no longer uses the column that stored the image. Now I want to completely delete that column from the database to keep the Linq queries from wasting time and resources pulling in these huge files.
I searched my project for every reference to the column and removed it, then deleted the column from the database (don't worry, I have plenty of backups of everything). When I did this I began to get error messages about an invalid column name for the column I deleted.
So my question is, how the heck do you modify the structure of a table when using Linq?
You need to be sure to remove the column from the DBML itself. Just view the DBML in the designer and delete the appropriate column. You would not get any error at compile time since it does not check to see if the DBML actually matches up with the database during compiliation.
Just delete the table from the Linq-Sql designer, then add it again.
If you removed the file from the dbml file, and it didn't pick up on the change, go ahead and right-click the dbml file and choose "Run Custom Tool". Note that if you look at the file's properties (right-click on the entry in solution explorer) you should see the custom tool listed as "MSLinqToSQLGenerator".
Worst case: If you expand the file, and look at the "dbmlfilename.designer.cs" file you should be able to find the field/column name in question. Go ahead and delete it from that file. (one property (with attribute and getter/setter) and one field with the same name (starting with an _ character).
It's the attribute on the property in the designer file that causes the runtime exception.