|
System.Data.OleDb.OleDbException: 'No value given for one or more of the required parameters.'
|
|
|
|
|
That cannot be true since there is no SQL command in the code you posted.
|
|
|
|
|
Hi All, trying to work with Java Access Bridge in c#, everything works fine however whenever i try to subscribe on dotnet framework version 4.5 and above e.g.
JabApi.MouseClickedDelegate mcd = new JabApi.MouseClickedDelegate(HandleMouseClickedDelegate);
JabApi.setMouseClickedFP(mcd);
Application crashes, but same code works fine on dotnet framework version 4.0.
Checked Event log : Faulting module name: windowsaccessbridge-64.dll
|
|
|
|
|
The "Bridge" appears to involve components (for testing) that are no longer supported. I'd think a # COM server or something would be more forward-looking.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I have a problem where C# cannot Create/Update/Delete through an ODATA web service running from D365BC.
PS I am using VS 2019, C# winforms.
Our company is going to use Dynamics 365 Business Central (D365BC), which uses the programming language AL.
AL is a nice language but some things we will simply prefer to do in C#.
In D365BC you can easily create tables and pages (objects that consume these tables). And for each page you can create a web service by simply clicking a checkbox. These web service can be used to communicate via SOAP/ODATA v3 and ODATA v4. All are available at the same time.
So creating a web service that allows communication with a table created in D365BC is fairly easy.
If I use the SOAP webservice I can perform all CRUD functions. But when I use ODATA (either v3 or v4) I can read from the web service but I cannot Create/Update or Delete. The reason that we may occasionally want to use ODATA, is that ODATA is faster than SOAP.
The code I have in D365BC:
A simple table where every field is a record in a SQL table.
table 50109 "Workers"
{
DataClassification = ToBeClassified;
fields
{
field(1; "No."; Code[20])
{
DataClassification = ToBeClassified;
}
field(10; "First name"; Text[50])
{
DataClassification = ToBeClassified;
}
field(20; "Last Name"; Text[50])
{
DataClassification = ToBeClassified;
}
field(40; FunctionName; Text[50])
{
DataClassification = ToBeClassified;
}
}
trigger OnInsert()
var
myInt: Integer;
begin
end;
trigger OnModify()
var
myInt: Integer;
begin
end;
trigger OnDelete()
var
myInt: Integer;
begin
end;
}
The card page that uses the table and has the ability to make a web service out of the used table.
page 50108 "Workers Card"
{
PageType = Card;
ApplicationArea = All;
UsageCategory = Administration;
SourceTable = Workers;
layout
{
area(Content)
{
group(General)
{
field("No."; "No.")
{
ApplicationArea = Basic;
Importance = Promoted;
}
field("First name"; "First name")
{
ApplicationArea = Basic;
}
field("Last name"; "Last name")
{
ApplicationArea = Basic;
}
field(FunctionName; FunctionName)
{
ApplicationArea = Basic;
}
}
}
}
}
Than there is a list page, that is used in D365BC to get a list of records, not really needed for the web service, but I provide it just to be complete.
page 50109 "Workers List"
{
PageType = List;
ApplicationArea = All;
UsageCategory = Lists;
SourceTable = Workers;
layout
{
area(Content)
{
repeater(Group)
{
field("No."; "No.")
{
ApplicationArea = Basic;
}
field("First name"; "First name")
{
ApplicationArea = Basic;
}
field("Last Name"; "Last Name")
{
ApplicationArea = Basic;
}
field(FunctionName; FunctionName)
{
ApplicationArea = Basic;
}
}
}
}
}
In order to be able to create the web service we need to provide a little xml file to D365BC. I provide this, just to be complete.
<?xml version = "1.0" encoding = "utf-8" ?>
<ExportedData>
<TenantWebServiceCollection>
<TenanatWebService>
<ObjectType>Page</ObjectType>
<ObjectID>50108</ObjectID>
<ServiceName>WorkersWS</ServiceName>
<Published>true</Published>
</TenanatWebService>
</TenantWebServiceCollection>
</ExportedData>
Using C3 to read from the ODATA web service is no problem:
listBox1.Items.Clear();
WorkersReadFromAlWebService = new List<WorkerClass>();
string _wsURL = "https://api.businesscentral.dynamics.com/v2.0/SomeFunfyGuid/Sandbox/WS/CRONUS%20NL/Page/WorkersWS";
string _userName = "UserName";
string _wsKey = "Password";
BasicHttpBinding _binding = new BasicHttpBinding();
_binding.Security.Mode = BasicHttpSecurityMode.Transport;
_binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
using (WorkersWS_PortClient _ws = new WorkersWS_PortClient(_binding, new EndpointAddress(_wsURL)))
{
_ws.ClientCredentials.UserName.UserName = _userName;
_ws.ClientCredentials.UserName.Password = _wsKey;
List<WorkersWS_Filter> _filters = new List<WorkersWS_Filter>();
WorkersWS_Filter _filter = new WorkersWS_Filter
{
Field = WorkersWS_Fields.No,
Criteria = "*"
};
_filters.Add(_filter);
try
{
foreach (WorkersWS _workerWS in _ws.ReadMultiple(_filters.ToArray(), "", 0))
{
WorkerClass _wc = new WorkerClass();
_wc.E_Tag = _workerWS.Key;
_wc.First_Name = _workerWS.First_name;
_wc.Last_Name = _workerWS.Last_Name;
_wc.FunctionName = _workerWS.FunctionName;
WorkersReadFromAlWebService.Add(_wc);
listBox1.Items.Add(_workerWS.Last_Name + " / " + _workerWS.First_name + " (No: " + _workerWS.No + ")");
}
}
catch (Exception _ex)
{
}
}
ClearWorker();
My C# attempt to Update or Create a new record in the table using the ODATA web service:
string _url = "https://api.businesscentral.dynamics.com/v2.0/SomeFunkyGuid/Sandbox/ODataV4/Company('CRONUS%20NL')/WorkersWS";
HttpWebRequest _request = (HttpWebRequest)WebRequest.Create(_url);
_request.ContentType = "application/json; charset=utf-8";
_request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes("UserName:Password"));
_request.Accept = "*/*";
_request.KeepAlive = true;
_request.Method = "PATCH";
string _etag = rtbE_Tag.Text;
_request.Headers["If-Match"] = String.Format("W/\"{0}\"", _etag);
string body = "{" + Environment.NewLine +
"\"No\":" + tbNo.Text + "," + Environment.NewLine +
"\"First_name\":\"" + tbFirstName.Text + "\"," + Environment.NewLine +
"\"Last_Name\":\"" + tbLastName.Text + "\"," + Environment.NewLine +
"\"FunctionName\":\"" + tbFunctionName.Text + "\"," + Environment.NewLine +
"}";
byte[] data = Encoding.ASCII.GetBytes(body);
try
{
_request.ContentLength = data.Length;
Stream requestStream = _request.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Close();
HttpWebResponse _response = _request.GetResponse() as HttpWebResponse;
Console.WriteLine(_response.StatusCode);
}
catch (Exception ex)
{
}
So it makes no difference if I use Patch, Put or Post (except for the error number).
I tried to get an anser through D365BC forums, but I simply get no reply (at least not a reply that is of any help).
Finding answers yourselves is like the verbal 'needle in the haystack'. D365BC uses the relative new language AL. And if you find something it usually is for Navision, which uses C/AL, which is completely different.
I also tried a completely different approach by using the Nuget package manager and see what ODATA packages are there.
Many of these are created for MVC (I am using Win Forms).
But I tried:
- Microsoft.OData.Data (for use with ODATA v3, It doesn't simply install on VS 2019, but using something that I found online I got it to install on VS 2019, but all these sample assume an ODATA web service without authentication. Using authentication, requires setting some settings in the OdataClient.odata.config file. Well this file isn't created (perhaps only when using MVC), if I create it myself and I set the settings for authentication, it simply does nothing. I get an authentication error, password/username not set)
- Microsoft.OData.Core (for use with ODATA v4, behaves exactly like the .DATA version (so same problems), again no luck)
- Simple.Odata.Client (couldn't get authenticated, which is a show stopper)
- tried a third one as well (forgot the name), but also simply using the authentication is a problem.
When I speak about this problem with some people they more or less all claim that there isn't much difference between SOAP and ODATA. Yet SOAP works and ODATA doesn't.
I hope there is someone who has experience with this and is willing and capable to help me.
I will end with the SOAP code that works and which we can use to update a record:
string _wsURL = "https://api.businesscentral.dynamics.com/v2.0/SomeFunkyGuid/Sandbox/WS/CRONUS%20NL/Page/WorkersWS";
string _userName = "Username";
string _wsKey = "Password";
BasicHttpBinding _binding = new BasicHttpBinding();
_binding.Security.Mode = BasicHttpSecurityMode.Transport;
_binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
using (WorkersWS_PortClient _ws = new WorkersWS_PortClient(_binding, new EndpointAddress(_wsURL)))
{
_ws.ClientCredentials.UserName.UserName = _userName;
_ws.ClientCredentials.UserName.Password = _wsKey;
try
{
WorkersWS _wws = _ws.Read(tbNo.Text);
if (_wws.No == tbNo.Text)
{
_wws.First_name = tbFirstName.Text;
_wws.Last_Name = tbLastName.Text;
_wws.FunctionName = tbFunctionName.Text;
_ws.Update(ref _wws);
if (_wws.No == tbNo.Text)
{
tbResult.Text = "Update success.";
}
}
}
catch (Exception _ex)
{
}
}
Kind regards,
Clemens Linders
|
|
|
|
|
Rather than building the request body by hand, you should use a JSON serializer to create it.
Add a NuGet package reference to JSON.NET[^], add a using directive for the Newtonsoft.Json namespace, and change your code to:
var body = new
{
No = tbNo.Text,
First_name = tbFirstName.Text,
Last_Name = tbLastName.Text,
FunctionName = tbFunctionName.Text,
};
string json = JsonConvert.SerializeObject(body);
byte[] data = Encoding.UTF8.GetBytes(json); NB: You'll want to use the UTF8 encoding rather than ASCII, since that's what you've declared in your content-type header.
I'd also be inclined to use the HttpClient class[^] rather than the low-level HttpWebRequest class:
Call a Web API From a .NET Client (C#) - ASP.NET 4.x | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
Thanks for your reply.
If I used the code you profided me but I cannot pass 'data' to _client as it expects a class and not Json data.
If I create a class and fill it, like in the MS Docs page you provided, than I get error 401 not authorized.
WorkersClass _data = new WorkersClass();
_data.E_Tag = string.Empty;
_data.No = tbNo.Text;
_data.First_name = tbFirstName.Text;
_data.Last_Name = tbLastName.Text;
_data.FunctionName = tbFunctionName.Text;
var url = await CreateWorkerAsync(_data);
static async Task<Uri> CreateWorkerAsync(WorkersClass _worker)
{
string _url = "https://api.businesscentral.dynamics.com/v2.0/SomeFunkyGuid/Sandbox/ODataV4/Company('CRONUS%20NL')/WorkersWebService";
string _userName = "UserName";
string _wsKey = "Password";
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(_userName, _wsKey);
HttpResponseMessage response = await _client.PostAsJsonAsync(_url, _worker);
response.EnsureSuccessStatusCode();
return response.Headers.Location;
}
I tried the following:
var body = new
{
E_Tag = string.Empty,
No = tbNo.Text,
First_name = tbFirstName.Text,
Last_Name = tbLastName.Text,
FunctionName = tbFunctionName.Text,
};
string json = JsonConvert.SerializeObject(body);
byte[] data = Encoding.UTF8.GetBytes(json);
var url = await CreateWorkerAsync(data);
The error I get is: Argument 1: cannot convert from byte[] to WorkersClass.
If I look at _client.PostAsJsonAsync, than I don't see a other solution where it says I can pass Json data?
I feel that I am close, but I think I miss the final step.
Hope you can help me.
Kind regards,
Clemens Linders
|
|
|
|
|
I was referring to the code from your original post, where you're constructing a JSON string manually:
Quote:
string body = "{" + Environment.NewLine +
"\"No\":" + tbNo.Text + "," + Environment.NewLine +
"\"First_name\":\"" + tbFirstName.Text + "\"," + Environment.NewLine +
"\"Last_Name\":\"" + tbLastName.Text + "\"," + Environment.NewLine +
"\"FunctionName\":\"" + tbFunctionName.Text + "\"," + Environment.NewLine +
"}";
byte[] data = Encoding.ASCII.GetBytes(body);
try
{
_request.ContentLength = data.Length;
Stream requestStream = _request.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Close();
HttpWebResponse _response = _request.GetResponse() as HttpWebResponse;
Console.WriteLine(_response.StatusCode);
}
catch (Exception ex)
{
} You don't need to worry about the JSON serialization with the HttpClient and the PostAsJsonAsync method - it handles the serialization for you.
You're getting a 401 error with your new code because you're passing the wrong values to the AuthenticationHeaderValue . The first parameter is the scheme, which should be "BASIC" , and the second is the parameter, which should be the combined username and password.
AuthenticationHeaderValue Constructor (System.Net.Http.Headers) | Microsoft Docs[^]
string _userName = "UserName";
string _wsKey = "Password";
byte[] authenticationParameter = Encoding.UTF8.GetBytes(_userName + ":" + _wsKey);
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authenticationParameter));
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
I changed the CreateWorkersAsync:
static async Task<Uri> CreateWorkerAsync(WorkersClass _worker)
{
string _url = "https://api.businesscentral.dynamics.com/v2.0/SomeFunkyGuid/Sandbox/ODataV4/Company('CRONUS%20NL')/WorkersWebService";
string _userName = "UserName";
string _wsKey = "Password";
byte[] _authenticationParameter = Encoding.UTF8.GetBytes(_userName + ":" + _wsKey);
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(_authenticationParameter));
HttpResponseMessage response = await _client.PostAsJsonAsync(_url, _worker);
response.EnsureSuccessStatusCode();
return response.Headers.Location;
}
I didn't make any other changes.
I now no longer get the error 401 Not Authorized.
Now I get the error: 400 Bad request
We're one step closer.
Do you have any idea why I could get this Bad request??
Kind regards,
Clemens Linders
|
|
|
|
|
A 400 error would suggest that the server doesn't recognise the request format.
Are you certain they accept JSON requests? Your original post mentioned a SOAP request, which is a dialect of XML. If they only support SOAP requests, you won't be able to post JSON data to the service.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
I am pretty sure that Json shouldn't be a problem, because when I read the data I use a Json deserializer.
There really are three different kind of web services:
- SOAP
- ODATA v3
- ODATA v4
This is the working code I use to read data using the ODATA V4 web service:
listBox1.Items.Clear();
WorkersReadFromAlWebService = new List<WorkerClass>();
string _url = "https://api.businesscentral.dynamics.com/v2.0/SomeFunkyGuid/Sandbox/ODataV4/Company('CRONUS%20NL')/WorkersWebService";
HttpWebRequest _request = (HttpWebRequest)WebRequest.Create(_url);
_request.ContentType = "application/json; charset=utf-8";
_request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes("UserName:Password"));
_request.PreAuthenticate = true;
HttpWebResponse _response = _request.GetResponse() as HttpWebResponse;
using (Stream _responseStream = _response.GetResponseStream())
{
StreamReader _reader = new StreamReader(_responseStream, Encoding.UTF8);
string _content = _reader.ReadToEnd();
string _jasonPart = GetJsonPartMultiRecord(_content);
List<WorkerClass> _jWorkers = JsonConvert.DeserializeObject<List<WorkerClass>>(_jasonPart);
foreach (var _worker in _jWorkers)
{
WorkersReadFromAlWebService.Add(_worker);
listBox1.Items.Add(_worker.Last_Name + " / " + _worker.First_name + " (No: " + _worker.No + ")");
}
}
ClearWorker();
|
|
|
|
|
I have 2 pdf files pdf1 and pdf 2.I want to compare both pdf and should give result as 2 pdf outputs.
The 2 output pdf ,the changes should be highlighted in some color.say for output 1 -red color and output 2 pdf-green color for the change
Eg: input pdf 1 - text is :- I am anoop
input pdf 2 - text is :- I am aneesh
so the output should be as follows:
output pdf 3: I am anoop
output pdf 3: I am aneesh
means text anoop is changed to aneesh.So anoop in red color and aneesh in green color. Please provide the c# code for this.
|
|
|
|
|
No. This is not a code-to-order service.
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I'd suggest to read this: How to compare strings - C# Guide | Microsoft Docs and write a method which will beet your criteria for string comparison. At this moment you need to decide if below strings are equal or not:
I am anoop
I Am anOop
I aM Anoop
I am anoOP
i AM anoop
I Am ANoOP
i aM anOop
When you accomplish string comparison then you'll be ready to go further.
|
|
|
|
|
Looks like you've got a rival for this programming language[^] there.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Hi, I am having a hard time understanding some basic concepts in real time systems. I have tried reading up on it but when viewing a concrete system I can't really understand it.
The application prints the time, student name, student number and semester year as given in the setup in the program runs a certain amount of loops for all tasks.
Scheduler set up:
Name Delay
Thread#1 95ms
Thread#3 187ms
Thread#5 463ms
When code is executed it looks like this.
Print Out:
[T1]:11:30:45:808[T3]:11:30:45:825[T5]:11:30:45:825[T1]:Mark Johnson[T1]:152585[T3]:Mark Johnson[T1]:2020
[T5]:Mark Johnson[T1]:2020
[T5]:Mark Johnson[T1]:11:30:45:949[T3]:152585[T1]:Mark Johnson[T1]:2020
[T3]:2020[T5]:152585[T1]:2020[T3]:2020
What are the real time requirements of this application?
|
|
|
|
|
Windows is not and never has been a real time system: it's a multithreaded preemptive scheduling system, and that's different.
Thread delays aren't absolute values, they are minimum values: the thread will delay for at least Xms, and will be available to run from that point - but that doesn't mean it will run immediately, or even soon, depending on other threads in the system and the number of cores available to process them.
As the "Threads : Cores" ratio rises, more and more threads get delayed more and more.
You have no direct control at all over when a thread will run: all you can do is say "wait at least this long"; you can't even guarantee that a thread will complete an operation before a second thread gets in there - so when you are sharing a single resource (such as the console) between multiple threads, you can't even guarantee that each message you see will be complete, much less in an order you want!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi Original Griff, the question here is to analyze the system based on real-time requirements. The requirements will be any factor that may affect the running time of the tasks.The real-time involve tasks running in parallel, any common resources used by the system that will affect the timing and the time used by the application.
You are saying here that windows is not a real time system, but this is an app created to simulate a real time system that has some tasks running. That's a different thing inst it ?
If one disregards the CPU and computer memory which other resources are these tasks sharing when running?
|
|
|
|
|
What do you think?
It's your homework after all, not mine!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
"Real-time" is like an ATM; you want your cash NOW.
Anything other than "real-time", means stuff might go into a "queue" for a while before it get processed, if there is "other" stuff that also needs doing.
As for "your" app, no one knows what it's doing so no one can tell you if it has a "real-time" requirement or not.
And simply printing the same static information over and over isn't anything; it's just nonsense.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
auting82 wrote: What are the real time requirements of this application? There are not any real time requirements, since all you are doing is printing some general information about people in your database.
|
|
|
|
|
Hi
this is shyam from hyderabad city
request to provide the c# code related to multiple csv file into datatable or database
of mssql database
thanks in advance
|
|
|
|
|
Sorry, these forums are not suited for code requests. There exist some sites where you can rent coders, but CP isn't one of them.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
I have a Web API to send SMS to customers. Web API is up and running 24/7/365. Web API is running fine without any issues.
However, I am invoking the API everytime through PostMan tool. In order to avoid this manual intervention, I have written a console application, but that console application sometimes works, sometimes didn't. it stops abruptly without any reason, I tried to catch error, but no effect. The application has to run automatically with an interval of 5 minutes in day. Every 5 minute it has to run. If already previous task is running, then no need to start a new task. I have implemented this by using a ProcessMap table in Sql DB. So each time it starts, it checks if any sms task is running. if running,it will not start new, otherwise starts a new task.
My question is , is this the correct way to invoke the API automatically or is there any other better way to do this? Kindly hep.
|
|
|
|
|