I'm facing a problem with my console application. I want to read info from Microsoft Access database and display it on console.
Here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.OleDb;
using System.Data.Sql;
namespace _1_uzd
{
class Program
{
static void Main(string[] args)
{
string ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;DataSource=\"studentu-db.accdb\"";
OleDbConnection con = new OleDbConnection(ConnectionString);
OleDbCommand cmd = new OleDbCommand("SELECT * FROM persona", con);
con.Open();
OleDbDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read())
{
Console.WriteLine(dataReader.GetInt32(0) + "\t" + dataReader.GetString(1) + "\t" + dataReader.GetString(2));
}
con.Close();
Console.ReadLine();
}
}
}
It should work but when I debug, the error message is shown: "OleDbExeption was unhandled. Could not find installable ISAM"...Where is the problem?
PS: I'm using Microsoft Access 2007, it that makes any sense,
your connection string is not proper. that is main reason this error comes.
Try to correct connection string syntax as per http://www.connectionstrings.com/access/
Try with physical path like "C:\studentu-db.accdb" and if you are trying to locate access database from local folder then write "|DataDirectory|\studentu-db.accdb"
Related
We have the following mixed-environment scenario (Azure and LAN):
Azure Web App calls a method in the Azure API (triggered by some user action in the web app).
This Azure API then establishes a SignalR HubContext connection .
The HubContext broadcasts a message.
The SignalR client (consuming the message) is a Windows Service installed on a machine on the LAN, behind the firewall.
Our client is complaining that the connection often breaks, and therefore several messages are missing on a daily basis.
Here is a test method in the Azure API, which attempts to broadcast a message:
using Microsoft.AspNet.SignalR;
using System;
using System.IO;
using System.Net.Http.Headers;
using System.Reflection;
using System.Runtime.Caching;
using System.Text;
using System.Web.Http;
using System.Xml;
...
namespace MyTestAPI.Controllers
[AllowCrossSiteJson]
[RoutePrefix("api/Test")]
public class HL7Controller : ApiController
[HttpGet]
[Route("TestSignalR")]
public IHttpActionResult TestSignalR()
{
string reportData = $"<TestReport>This is a test message generated on { DateTime.Now }.</TestReport>";
var hubContext = GlobalHost.ConnectionManager.GetHubContext<HL7Hub>();
hubContext.Clients.All.SendReportData(reportData);
return Ok(reportData);
}
...
}
And in the client's environment, there's a Win Service installed - it acts as the SignalR Client
And here's a snippet of our H..NotificationsService solution (vs2019, Framework 4.6.1)
using log4net.Ext.EventID;
using Microsoft.AspNet.SignalR.Client;
using System;
using System.Configuration;
using System.Diagnostics;
using System.Net;
using System.ServiceProcess;
using System.Threading;
namespace H_NotificationSrv
{
public partial class H_NotificationService : ServiceBase
public async void StartListner()
{
try
{
var hubConnection = new HubConnection(hl7APIUrl);
hubConnection.Credentials = CredentialCache.DefaultNetworkCredentials;
var hubProxy = hubConnection.CreateHubProxy("MyTestHub");
hubProxy.On<string>("SendReportData", reportData =>
{
SendReportDataToSomeone(reportData);
});
await hubConnection.Start();
}
catch (Exception ex)
{
string errorMessage = ex.Message;
if (ex.InnerException != null)
errorMessage += " Inner Exception: " + ex.InnerException.Message;
applog.Error(errorMessage);
}
}
}
}
I try to make a listener on windows event logs, but I need to recognize IIS events in it and determine its application pool.
could I do that according to this code ??? by process id for example or any thing else.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Threading;
using System.DirectoryServices;
using Microsoft.Web;
using Microsoft.Web.Administration;
namespace EventLogEnt
{
class Program
{
static AutoResetEvent signal;
static void Main(string[] args)
{
// create new log
signal = new AutoResetEvent(false);
EventLog myNewLog = new EventLog("Application", "TIS3", "Outlook");
myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
myNewLog.EnableRaisingEvents = true;
myNewLog.WriteEntry("Test message", EventLogEntryType.Information);
signal.WaitOne();
Console.ReadKey();
}
public static void MyOnEntryWritten(object source, EntryWrittenEventArgs e)
{
Console.WriteLine(e.Entry.Message);
Console.WriteLine("the entry type: " + e.Entry.EntryType);
Console.WriteLine("---------------------------------------------");
signal.Set();
}
}
}
Good day!
I try to learn ASP MVC vNext (6?) , so i use this tutorial, but when i type this code:
[HttpPost]
public void CreateTodoItem([FromBody] TodoItem item)
{
item.Id = 1 + _items.Max(x => (int?)x.Id) ?? 0;
_items.Add(item);
string url = Url.RouteUrl("GetByIdRoute", new { id = item.Id },
Request.Scheme, Request.Host.ToUriComponent());
Context.Response.StatusCode = 201;
Context.Response.Headers["Location"] = url;
}
I have the error message:'Url' does not contain a definition for 'RouteUrl'.
I add this usings, but it does no help:
using Microsoft.AspNet.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Net.Http.Server;
using System.Runtime.Remoting.Contexts;
using System.Security.Policy;
Please, help me to fix this errors!
Url.RouteUrl is in the System.Web.Mvc.dll so add using System.Web.Mvc;
looking back at this Url.RouteUrl is in the Microsoft.AspNet.Mvc namespace in MVC6. you seem to have that so I'm not 100% sure. could be missing reference files or other compile errors.
I am trying to query a customer in qbo with a name that has an ' for example (Joe's Shop) and getting the above error.
here is the code.
IEnumerable<Customer> customers = customerQueryService.Where(c => c.DisplayName =="Joe's Shop");
if (customers.Count()!=0 )
{
customer = customers.First();
}
return customer;
Please use backslash to escape the single quote.
"Joe\'s Shop"
Thanks
using Intuit.Ipp.Core;
using Intuit.Ipp.Data;
using Intuit.Ipp.LinqExtender;
using Intuit.Ipp.QueryFilter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
static class SampleCalls
{
public static Customer QueryCustomerByDisplayName(ServiceContext context, string displayName) {
displayName = displayName.Replace("'", "\\'"); //Escape special characters
QueryService<Customer> customerQueryService = new QueryService<Customer>(context);
return customerQueryService.Where(m => m.DisplayName == displayName).FirstOrDefault();
}
}
I have created a webservice in Visual studio 2010.I have created a database with a table which contains commands and their description.My program is:
My class:-DataHelper.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for DataHelper
/// </summary>
public class DataHelper
{
public static string GetData(string Command)
{
string Explanation = " ";
SqlConnection con = new SqlConnection(#"Data Source=CSS-L3-D008;Initial Catalog=works1;Integrated Security=true;");
SqlCommand cmd = new SqlCommand("Select Explanation from Data1 where Command= '" + Command.ToUpper() + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Explanation = dr["Explanation"].ToString();
}
dr.Close();
con.Close();
return Explanation;
}
}
And Service1.asmx
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService
Private Property DataHelper As Object
<WebMethod()>
Public Function HelloWorld() As String
Return "Hello World"
End Function
<WebMethod()>
Public Function GetData(Command) As String
Return DataHelper.GetData(Command)
End Function
End Class
the problem is that wen i run it i am getting both webmethods HelloWorld and GetData but GetData is not working.When i click HelloWorld() i get invoke method and it runs properly.But when i click GetData() i get invoke button but then it shows
"The test form is only available for methods with primitive types as parameters."
Actually it should give a box where i can enter the command and the description should be returned from the sql server.Please help me.
Should that GetData method in the service declare the type of the Command parameter?:
<WebMethod()>
Public Function GetData(Command As String) As String
Return DataHelper.GetData(Command)
End Function