|
hello
I need to provide facility for Matlab to do bulk insert to SQL. Matlab provides ways to load .NET assembly and call .NET methods:
Assembly reference: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/net.addassembly.html
Method calls: http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/brpb58s-1.html#brpca5n-1
However, we can't pass "Cell Array":
Example:
<br />
% 2 Dimensional array of numbers<br />
a=[1 2 3; 3 4 5; 6 7 8]<br />
aa=[1.1 2.2 3.3; 4.4 5.5 6.6; 7.7 8.8 9.9]<br />
% Single dimension string array (2D not permitted)<br />
b={'aaa0'; 'bbb0'; 'ccc0'}<br />
bb={'aaa0','aaa1'; 'bbb0', 'bbb1'; 'ccc0', 'ccc1'}<br />
<br />
c={'20100701' 1.11 2.22; '20100702' 3.33 4.44; '20100703' 5.55 6.66;}<br />
<br />
"c" above is cellarray
Now, my only option is to wrap bulk insert logic in ATL COM server, and call from Matlab as such:
dbServer = actxserver('MyDBComServer');
The first article below shows how to build a simple ATL server in C++ but:
PROBLEM 1: sample shows only passing simple type such as string/BSTR - I need to pass a Matlab CellArray across (For this problem... I don't have much clue how CellArray is represented in memory as thereby passed across Matlab/COM/.NET borders)
PROBLEM 2: I don't have access to .NET System.Data.SqlClient.SqlBulkCopy (For this problem can I packaged ATL done by C#? From Visual Studio 2008 \ New Project, I can find "ATL Projects" only under VC++. Is my option a COM server without ATL as indicated in Third Reference below? I am inheriting an old VB.NET COM project but having problem getting it registered, but it must be possible)
PROBLEM 3: Windows 2003 64 bit - any deadend you know?
http://digital-clipart.de/KB/COM/SimpleCOM.aspx[^]
1..2..3 ways of integrating MATLAB with the .NET[^]
http://msdn.microsoft.com/en-us/library/aa645712(v=VS.71).aspx[^]
dev
|
|
|
|
|
Good Morning all,
Currently I try to accomplish to load a DLL (filename and path) as an assembly to be available to all classes in my project.
This is because one of our third party classes makes a call to an unreferenced dll and therefore fails.
I already tried different things:
- loading the assembly into the AppDomain.CurrentDomain
- instanciating objects of the required type via reflection
- I tried different locations for doing the above mentioned things (Startproject, directly before the error occurs, etc)
All solutions loaded the assemblies, but the type seems inaccessible to the third party class.
In VisualStudio 2010 in the output window I can see the line saying that the dll is loaded.
Funny (yeah, not really funny, quire obvious) is that when I copy the dll into the executing directory or reference it via the Project References everything works fine. Unfortunately this is not a solution, because we use MEF to import such classes (third party) into our Application.
I thought about copying the dll to the application folder because thanks to MEF I can get a handle on every DLL necessary... but that would be quite ugly, wouldn't it?
I guess I just forget about something...but it doesn't pop into my mind..
Any help is kindly appreciated,
best regards
Andy
|
|
|
|
|
From what I understand, using add-ins, plug-ins, etc. only works with code that is designed to work that way.
What's "MEF"?
|
|
|
|
|
Sorry, I don't get it...
MEF means "Managed Extensibility Framework", you can export and import certain types (thats a really low level description) to extend "things".
best regards
Andy
|
|
|
|
|
In my experience, you can't just plug-in a class that wasn't designed to be plugged-in. Generally, you create an interface that describes the plug-in. A class that is intended to be used as a plug-in implements the interface. Your application loads the class' assembly and uses it via the interface. The interface has to be declared separately from the plug-in.
Does the class implement an interface or base class that you can use? What sorts of things are you trying to do with the class?
|
|
|
|
|
Actually that is exactly what I am trying to do.
The Third-Party-Tool (ref. TPT) requires an Interface to interact with.
Now I use MEF to import all available classes that explicitly export this Interface and store them in a catalogue (Assembly-Catalogue).
So far so good, everything works fine as long as I stick to the current assembly to build the catalogue from.
Now I've added other dll's that expose (export) the above mentioned Interface. The path of this dll is stored in a XML file in order to retrieve them later and add the found dlls to the Cataloge (its now a mix of the Assembly and the added dll's).
Now I can populate additional "actions"... till here, everything is fine.
The TPT stores the name of the dll (when an action is selected) and when it tries to "grab" it again later (when the action is executed) it tries to resolve the dll, which fails.
Here is the point where I have already overwritten (extended) the methods for Object-Retrival used in the TPT.
That's the story so far
|
|
|
|
|
hoernchenmeister wrote: that is exactly what I am trying to do
OK, good.
hoernchenmeister wrote: Now I can populate additional "actions"...
I'm unclear on what you mean by that. Do you mean load other plug-ins?
hoernchenmeister wrote: The TPT stores the name of the dll
But there could be multiple suitable classes in one dll/assembly; how can that work?
hoernchenmeister wrote: which fails
Do you get an Exception?
|
|
|
|
|
PIEBALDconsult wrote:
OK, good.
Indeed
PIEBALDconsult wrote: I'm unclear on what you mean by that. Do you mean load other plug-ins?
Yes, that is right. What I was referring to as "action" is a class that implements the IAction Interface (the interface required by the TPT).
So I basically load all classes providing the IAction interface into, lets say an admin interface where users can select the type of action they want to execute.
That's the part that actually works
The TPT then takes the "selected and configured action" and stores it.
The TPT requires an action of type IAction for beeing able to do so.
Even that works, actions are created from the XML catalogue and stored.
But when the action is finally executed the TPT tries to build a valid object from the storage (IAction). It uses the fullname and it's own Object-Builder (which I have already extended) to build the action-object and fires it.
Here I get the exception which is that the referenced assembly can not be found...
That only works when referencing the DLL from the xml-catalogue or copying it into the bin directory of the current project.
|
|
|
|
|
Then I don't know.
hoernchenmeister wrote: which I have already extended
Maybe start there. Undo what you did and see what happens.
|
|
|
|
|
That's ok, but anyway, thank you for thinking about this.
I'll give it a rest, sometimes problem become more "solvable" if a day or two pass by
|
|
|
|
|
"... makes a call to an unreferenced dll and therefore fails":
Have you tried loading that "unreferenced dll" before, or putting that dll to the GAC?
|
|
|
|
|
Yes, I did that.
I know the path of the dll and created instances via Activator.
In the meantime I figured out that the third party tool uses incompatible object-detection. I tried to overwrite that plugging in a different Type-Loader, but somehow it's not letting me tweak the base which seems to cause the problem.
Due to the fact that when I reference the dll in the VS2010 project itself everything works, I thought about creating a reference in code, based on the path of the missing dll at runtime.
Would that be possible?
...just pretending it was referenced...
Maybe before the tool makes its first call to the dll... I hope I could express myself clearly (sorry, not a native speaker)
Unfortunately GAC isn't an option due to structural matters.
|
|
|
|
|
Hello,
Please I want to get the upperbound of a dynamic array,
is there a function in c# to achive this?
thanks.
|
|
|
|
|
Dynamic Array[^]
Sathesh.
Blessed is the season which engages the whole world in a conspiracy of love.
|
|
|
|
|
You can find how many elements are in an array with the Length property.
C# doesn't have dynamic arrays - they are all fixed when you declare them, but you can fake it by creating a new array and copying the old elements to it. This is not a dynamic array however, as only the references you specifically change have the new size.
int[] orig = new int[] { 1, 2, 3, 4, 5, 6 };
int[] copy = orig;
int[] temp = new int[10];
for (int i = 0; i < copy.Length; i++)
{
temp[i] = copy[i];
}
copy = temp;
"copy" now refers to an array of ints with ten elements, but "orig" tsill referes to an array of six.
If you want a dynamic array like structure, you would be better off using a List<T> which has a ToArray method if you need it.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
OriginalGriff wrote: If you want a dynamic array like structure, you would be better off using a List<t>
Or switch to VB?
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
riced wrote: Or switch to VB?
Wash your keyboard out with soap!
I would never recommend anyone switch to VB.
Well, except Estate Agents.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
The smiley saved you from a 1 vote
ragnaroknrol The Internet is For Porn[^]
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
Thanks all,
I discovered that when using the foreach... loop to access
an array, you don't need to know the dimension before hand.
it works great.
thanks again for your contributions
|
|
|
|
|
Where did you find a dynamic array?
|
|
|
|
|
He looked under the VB sofa and there it was.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
Hi everyone,
I have the following issue. I use the following code to retrieve all data row from an mssql database and during the process I update some values.
The issue I have is that it only updates the first row in the database. All other rows which should be updated (field: WEB_OBEZ,...) are NULL.
Does someone have an idea or can explain why it only updates the first row ?
Thank you very much!
private string FixOBez()
{
SqlConnection dbconn = new SqlConnection(this.sqlconn);
try
{
dbconn.Open();
SqlDataReader sqlreader = null;
SqlCommand mycmd = new SqlCommand("SELECT * FROM dbo.testdata", dbconn);
sqlreader = mycmd.ExecuteReader();
while (sqlreader.Read())
{
string obez = sqlreader["O_BEZ"].ToString();
string okuerzel = sqlreader["O_KURZ"].ToString();
string[] lines = GetNewOBez(obez);
SqlCommand sql2 = new SqlCommand("UPDATE dbo.testdata SET WEB_OBEZ1 = '" + lines[0] + "',WEB_OBEZ2 = '" + lines[1] + "',WEB_OBEZ3 = '" + lines[2] + "' WHERE O_KURZ = '" + okuerzel + "'",dbconn);
sql2.ExecuteNonQuery();
return "OK";
}
}
catch (Exception ex)
{
return ex.Message;
}
return "OK";
}
Bye,
ANeuby
|
|
|
|
|
Found the issue. The return was in the wrong line.
|
|
|
|
|
I have Gridview with AutoGenerateColumns to true(as I don't know how many columns will come). From database I am getting binary data. When I bind data table to gridview it displays checkbox with checked and unchecked. I need to display as 0 or 1. How can I do this?
|
|
|
|
|
You can do it in multiple ways like - converting that boolean property to a string property in gridview source object, make use of template in griview.
|
|
|
|