Well, first of all sorry about this question it must be pretty straight forward for you guys but I'm struggling myself on it, and I need to make it work :(
Well I'm trying t o use DataSet on my application
and when I render it I got:
The type 'System.Data.DataSet' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data
in my application System.Data is already being referenced from C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll
and I'm using on my using clauses as well
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
This DataSet is a response from a Webservice
So any Ideas on how to fix this problem?
PS. I don't know if it helps, but I'm using nHaml to render my view
Thanks a lot
UPDATE:
The only solution I found for now was to instead passing a DataSet to the view converter the DataSet to a
<List<List<String>>
and pass a loop through the entire DataSet like this
List<List<String>> myList = new List<List<String>>();
foreach (DataRow row in dsTrades.Tables[0].Rows)
{
List<String> myListColumns = new List<String>();
for (var index = 0; index < dsTrades.Tables[0].Columns.Count; index ++)
{
myListColumns.Add(row[index].ToString());
}
myList.Add(myListColumns);
}
// THIS SHOULD BE THE DATASET AND NOW
// IT'S CONVERTED TO A LIST WITH STRINGS LIST INSIDE
viewModel.Trades = myList;
return View(viewModel);
Actually this is completely crazy ins't it?
All this job could be easily done into the view if using DataSet directly
I hope anyone can help me with a more simplistic way to do it
Thank you :)
UPDATE (SOLUTION)
Simon's answer was really effective and it worked on the first try after adding namespaces for System.Data and System.Xml but at the same time, Josh's answer present a very nice and cool way to work with DataSets, which on my opinion works much better and I think I'll go for it now.
Thanks for you help
try adding an explicit reference to System.Data in your nhaml configuration
<?xml version="1.0"?>
<configuration>
...
<configSections>
<section name="nhaml" type="NHaml.Configuration.NHamlConfigurationSection, NHaml"/>
</configSections>
...
<nhaml autoRecompile="true">
<assemblies>
<clear/>
...
<add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</assemblies>
<namespaces>
<clear/>
...
<add namespace="System.Data"/>
</namespaces>
</nhaml>
obviously replacing "..." with your other references and config
The only thing I could think of is that in the context of the page, the System.Data reference is not visible.
Try adding the namespace in your web.config:
<pages>
<controls />
<namespaces>
<add namespace="System.Data"/>
</namespaces>
</pages>
I know it's not really part of your question, but I would recommend building a class filled with properties representing the fields in your datatable. Using Linq, you can easily convert your rows into the class object and return a list of them. Here's some rough (and uncompiled) code.
[Serializable]
public class MyClass
{
public string Property1 { get; set; }
public string Property1 { get; set; }
}
You want it to be serializable so your web service can return it as xml or json (however you are returning it). The linq would look something like this:
var result = from r in dataSet.Table[0].Rows.AsEnumerable()
select new MyClass() {
Property1 = r["Field1"].ToString()
Property2 = r["Field2"].ToString()
};
return result.ToList();
In my personal experience, DataSets tend to be resource hogs. Also, Linq will be more efficient than your for loops.
Hope this helps.
Delete the Reffrence(system.Data) ..and Add the same reffrence again .. it might be work..
Related
I have a enum:
[Flags]
public enum ResultType {
Success = 0x01,
Failed = 0x02,
Comment = 0x03
}
How do I access it in my MVC4 Razor View? Something like this:
You have: #ResultType.Failed!!!
That will work fine.
However, you need to import the namespace:
#using Some.Namespace;
The answer that #SLacks gave does work, but I'd like to expand on it. I keep all of my app enums in a single file (for maintainability) and you can add the namespace of that (and anything else you consistently need in views) in the ~/Views/Web.Config or other relevant config file. This will allow you to use the enums without having to remember to add the namespaces, and is especially helpful if you are using visual studio scaffolding.
<namespaces>
<add namespace="YourApp.Enums" />
</namespaces>
I am sure, I am missing something obvious here. I am trying to get my sample RhinoETL based app to talk to a sql server. It just would not do that. I am following the video tutorial by Paul Barriere.
using Rhino.Etl.Core.Operations;
namespace RhinoETLTest01.Operations
{
class WriteJoinedRecordsToSql : SqlBulkInsertOperation
{
public WriteJoinedRecordsToSql() : base("TestEtl", "dbo.NameAndTitle") {}
protected override void PrepareSchema()
{
Schema["Id"] = typeof(int);
Schema["FullName"] = typeof (string);
Schema["JobTitle"] = typeof (string);
}
}
}
I am able to merge data from 2 files and write them into a 3rd text file. But, I cant get the merged records to get into a sql table. What am I missing please? My App.Config has the correct connectionstring setting.
Thanks
I had a similar problem. The solution was to fully qualify the sql provider in the connection string in the App.config
<configuration>
<connectionStrings>
<add name="TestEtl"
connectionString="Data Source=TestEtl;Initial Catalog=NameAndTitle;Integrated Security=SSPI;Timeout=300;"
providerName="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</connectionStrings>
</configuration>
After that check your sql commands for correctness. I downloaded the full source and stepped through to find these and related issues.
I'm done trying to Google for this. I have installed SQL Server CE 4.0, and have EF 4.1, but I can't get a proper connection string. Nothing on connectionstrings.com applies to me.
I just want to create a SqlCeEngine object, but no matter what I try I get some exception. Most recently it's been
Unknown connection option in connection string
with either "metadata", "app", "provider", or "provider connection string" after it. I know EF requires metadata in the connection string. And I can't imagine how anything could do without "provider connection string".
So far I have this:
<add name="DBContext"
connectionString="provider connection string="Data Source=MyDbFile.sdf;Persist Security Info=False;""
providerName="System.Data.EntityClient" />
At one point I had it with metadata:
<add name="DBContext"
connectionString="metadata=res://*/Data.DBContext.csdl|res://*/Data.DBContext.ssdl|res://*/Data.DBContext.msl;provider=System.Data.SqlClient;provider connection string="Data Source=MyDbFile.sdf;Persist Security Info=False;""
providerName="System.Data.EntityClient" />
Does it need metadata or not? What goes in the "app" part of the connection string? What should the provider be, System.Data.SqlClient or some SQL Server CE version? (which I still can't find when I try to add references. My add references window still only contains System.Data.SqlServerCe version 3.5.1.0.) Or nothing?
And what should go in the providerName attribute? Is System.Data.EntityClient correct? It's like there are 10 different variables here and every combination gives me a new equally mysterious error, none of which turns up anything useful on Google. I'm at my wits' end. Is this even possible?
You could try this in your App.config file (EF5 Code first migrations and SQL Server CE 4.0):
<connectionStrings>
<add name="DefaultConnection"
providerName="System.Data.SqlServerCe.4.0"
connectionString="Data Source=|DataDirectory|\Data\ProjectDb.sdf"/>
</connectionStrings>
And in you ProjectDb class:
class ProjectDb : DbContext
{
public ProjectDb()
: base("DefaultConnection")
{
}
}
It will work like a charm.
You can find more information here: http://blogs.msdn.com/b/adonet/archive/2011/01/27/using-dbcontext-in-ef-feature-ctp5-part-2-connections-and-models.aspx
I’d stuck with the same problem on Entity Framework 5.0 Code First approach with SQL Server Compact Edition 4.0
To solve it I pass instance of SqlCeConnection to DbContext's constructor:
public class Storage : DbContext
{
public Storage()
: base(new SqlCeConnection("Data Source=Database.sdf;Persist Security Info=False;"),
contextOwnsConnection: true)
{ }
//...
}
If you don’t want to inline connection string you could get it from App.config through ConfigurationManager
And of course you should add reference to the right version of System.Data.SqlServerCe (look inside Extentions tab in the Add Reference dialog)
This TechNet article outlines the steps for using EF with SQL Server Compact. This line jumped out at me, and may solve your problems:
make sure that provider=System.Data.SqlServerCe.3.5 in the connection
string.
(I would assume that you would want 4.0 instead of 3.5)
Give that a try and see how things go.
The Lu55's solution didn't work for me, but I found fow to fix it. To still use the automatic code generation (which can overwrite changes in a generated file), I added one more file with the following code:
using System.Data.Entity;
using System.Data.Objects;
namespace MyProject.Data
{
internal partial class Entities : DbContext
{
public Entities(string connectionString)
: base(
new ObjectContext(
#"metadata=res://*/Data.Model.csdl|
res://*/Data.Model.ssdl|
res://*/Data.Model.msl;
provider=System.Data.SqlServerCe.4.0;"),
true)
{
Database.Connection.ConnectionString = connectionString;
}
}
}
You have mixed a bit.
For SQL Server CE connection string can be quite easy (possibly replace DbContext with YourNameSpace.DbContextName):
<add name="DbContext"
connectionString="MyDbFile.sdf"
providerName="System.Data.SqlServerCe.4.0" />
I also had a lot of trouble with connections, so I did the following:
installed Entity Framework for SQL Server CE
Checked that web.config contains provider with invariant System.Data.SqlServerCe.4.0
Verified that there are NO string fields (which will be represented as columns in db) with length max or mode than 4000 symbols (to add restriction use annotation [MaxLength(4000)], by default == MAX)
Metadata are necessary when you use database-first model instead of code-first, so there is .edmx file which represents generated model of the database.
Has anyone tried to run Redmine using IronRuby? Is it possible?
I think the answer is NO at present... doing a bit of google searching I found various
people asking a few trying and some raising issues...
https://serverfault.com/questions/165539/redmine-in-ironruby
Currently, Redmine is only supported on Ruby 1.8.6 and 1.8.7 and on Ruby Enterprise Edition. There are currently efforts ongoing to have Redmine running on jRuby and Rubinius. As there are not that many core devs running windows, I would not assume that anyone actively works on IronRuby compatibility.
If you are willing to help and code needed patches, you are welcome to speak up on http://redmine.org.
Redmine, yaml files can't have % in them..
In my fruitless efforts to get redmine running on IronRuby one of the things i discovered were that the lines like these: "field_done_ratio: % Done" in the locale yaml files throwed exceptions. if i removed the "%" it worked (or at least i went one step further).
(gave up after these 16hours, my last obstacle were infinite redirection while accessing localhost:3000/, although accessing localhost:3000/login went well, but after that you couldn't do anything.. )
http://ironruby.codeplex.com/workitem/list/basic?size=2147483647
I attempted to get Redmine running on IronRuby with some success a few months ago. The version of Redmine I used was 0.9.3, IronRuby version was 1.0v4, SQL Server 2005 and it was hosted from IIS 6. This was actually a lot of work to get it up and running. I had to make minor modifications to a bunch of Redmine files. I also added some files that were not present in my download like new_rails_defaults.rb. Additionally, I had to get the IronRuby source from GitHub and modify it slightly to get IronRack working.
To get IIS to work I had to redirected all traffic to .Net for processing in the Redmine IIS WebApplication I created. This was done through adding an application extension mapping to "C:\Windows\Microsoft.NET\Framework\v2.0.50727aspnet_isapi.dll"
I then redirected all traffic to IronRack in my Web.config file.
<httpHandlers>
<clear />
<add path="*" verb="*" type="IronRuby.Rack.HttpHandlerFactory, IronRuby.Rack"/></httpHandlers>
This stopped IIS from being able to serve static files. To fix this I created the StaticFileHttpHandler.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
namespace StaticFileHttpHandler
{
public class StaticFileHttpHandler : IHttpHandler
{
#region IHttpHandler Members
public bool IsReusable
{
get
{
return true;
}
}
public void ProcessRequest(HttpContext context)
{
string staticFileUrl = context.Request.Url.LocalPath.Replace(#"/", #"\");
string staticFilePath = context.Server.MapPath(#"~\..\..\");
string defaultStaticFilePathForRemapping = #"\Redmine\public";
string defaultRootDirectoryForRemapping = #"\Redmine";
bool remapImage = !string.IsNullOrWhiteSpace(context.Request.QueryString.ToString());
if (staticFilePath.EndsWith(#"\"))
{
staticFilePath = staticFilePath.Substring(0, staticFilePath.Length - 1);
}
if (remapImage)
{
staticFilePath += (defaultStaticFilePathForRemapping + staticFileUrl.Replace(defaultRootDirectoryForRemapping, ""));
}
else
{
staticFilePath += staticFileUrl;
}
if (File.Exists(staticFilePath))
{
context.Response.ContentType = GetMimeType(staticFilePath);
context.Response.TransmitFile(staticFilePath);
}
else
{
context.Response.ContentType = "text/plain";
context.Response.Write("The File Does Not Exist!!! File: " + staticFilePath);
}
context.Response.Flush();
context.ApplicationInstance.CompleteRequest();
}
// Found Here: http://kseesharp.blogspot.com/2008/04/c-get-mimetype-from-file-name.html
private string GetMimeType(string fileName)
{
string mimeType = "application/unknown";
string ext = System.IO.Path.GetExtension(fileName).ToLower();
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
if (regKey != null && regKey.GetValue("Content Type") != null)
{
mimeType = regKey.GetValue("Content Type").ToString();
}
return mimeType;
}
#endregion
}
}
This needs to be added to the httpHandlers section as well. And for every static file type you want to it to be able to serve. An example of serving a PNG file is show below.
<httpHandlers>
<clear />
<add path="*.png" verb="*" type="StaticFileHttpHandler.StaticFileHttpHandler, StaticFileHttpHandler"/>
<add path="*" verb="*" type="IronRuby.Rack.HttpHandlerFactory, IronRuby.Rack"/></httpHandlers>
I also needed to make an images_controller.rb file to point the static files at.
# This is a place holder controller to allow for mapping static images
class ImagesController < ApplicationController
def index
0
end
end
Next all *.yml files need double qoutes around values with the percent sign.
field_done_ratio: "% ???????"
Additionally, I had to comment out all index creation and deletion in the database setup files in the db\migrate folder.
In conclusion, it is possible to get Redmine mostly working with IronRuby, IronRack, IIS 6, and SQL Server 2005 but not without some modifications.
I have a class like this:
public class RxNormFolderMgr
{
// properties
public string RxNormFolder { get { return ConfigurationSettings.AppSettings["rootFolder"].ToString(); } }
}
When I try to use it like this:
public class TestRxNormFolderManager : ColumnFixture
{
public string RxNormFolder()
{
RxNormFolderMgr folderMgr = new RxNormFolderMgr();
return folderMgr.RxNormFolder;
}
}
I get an error: "System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object." The AllKeys property for AppSettings is an array of zero length where I am expecting length of 1.
My app.config file in the project looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="rootFolder" value ="C:\RxNorm" />
<!-- Root folder must not end with slash. -->
</appSettings>
</configuration>
I know ConfigurationSettings.AppSettings is supposed to be obsolete and I should use ConfigurationManager.AppSettings, but I can't even get that to compile. I do have a reference in the project to System.configuration (c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.configuration.dll on my machine) and using statement at top of my code.
I am using Fitnesse to test the code, and that's when I get the error. It's my understanding that I should also place a copy of the app.config file in the Bin>Debug folder of the test fixtures project which I have done. So, I don't know why I'm getting this error still.
Please, help.
Also: try using the ConfigurationManager class instead of "ConfigurationSettings":
Use a check for NOT NULL first:
public class RxNormFolderMgr
{
// properties
public string RxNormFolder
{
get
{
if(ConfigurationManager.AppSettings["rootFolder"] != null)
{
return ConfigurationManager.AppSettings["rootFolder"].ToString();
}
return string.Empty;
}
}
}
Is this inside a class library assembly? Those never use their own app.config - but instead the use the host app's app.config (the app that uses the class library).
Marc
When you are testing with FitNesse, the actual executable running is "FitServer.exe" so AppSettings is looking for a "FitServer.exe.config" in the directory with FitServer.exe lives. So a quick and dirty solution is to copy your app.config there and rename it.
A better solution is to specify the app config as described here:
http://www.syterra.com/FitnesseDotNet/ApplicationConfigurationFile.html
or if you're using fitSharp (which is an enhancement of FitNesse.NET):
http://www.syterra.com/Fit/AppConfigFiles.html
Do not put it in appsettings. Use <connectionStrings>
example:
<appSettings/>
<connectionStrings>
<add name="NORTHWNDConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
string cnstr = ConfigurationManager.ConnectionStrings["NORTHWNDConnectionString"].ToString();