how to connect to oracle 10g using visual studio 2013 - oracle

I am new to oracle database, so i wanted to know how i can connect to an oracle 10g database using visual studio 2013.
Well i went to the server explorer and add connection where i chose the data source as Oracle Database and the data provider as .NET Framework Data Provider for OLE DB.
After that on testing the connection i get the error message as-
ORA-06413: Connection not open.
I searched a lot but couldn't find a proper answer to this question..
Can somebody help me out please.
OK so this is what I have done till now-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Hostel_Management_System
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_login_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection("Data Source=localhost;Initial Catalog=XE;Provider=SQLOLEDB;user-name=system;password=mypassword");
con.Open();
MessageBox.Show(con.State);
}
}
}
And I am getting a System.Data.OleDb.OleDbException in System.Data.dll.
Is this of any help??
[1]. http://i.stack.imgur.com/KUlZc.png

AFAIK the best way to create .net apps connected to Oracle is to use ODP.net and more specifically the managed driver which is available here.
The managed driver allows you to avoid installing an Oracle client on the machine your app runs on.
Sample code partially from the Oracle website:
using System;
using System.Data;
using Oracle.ManagedDataAccess.Client;
using System.Configuration;
class OracleConnectionSample
{
static void Main()
{
// Connect
const string connectionStringName = ...
string constr = ConfigurationManager.ConnectionStrings[connectionStringName].
ConnectionString;
using (var con = new OracleConnection(constr))
{
con.Open();
// Execute a SQL SELECT
using (OracleCommand cmd = con.CreateCommand())
{
cmd.CommandText = "select * from emp";
OracleDataReader reader = cmd.ExecuteReader();
// Print all employee numbers
while (reader.Read())
{
Console.WriteLine(reader.GetInt32(0));
}
}
}
}
}

Related

D365 FO connection from windows forms C# application

I need to make a connection from C# Windows Forms application to an on premise D365 FO.
So far, I created an Azure account and registered an application, so by now I have "Application (client) ID", "Directory (tenant) ID" and created a Client Secret.
What do I need to do to connect to D365 FO by using Data management package REST API?
Take a look at the Authorization Helper, which is part of the sample console app provided by Microsoft for the data management api (see the last sentence in https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/data-management-api). The Program.cs of the app shows how the Authentication Helper is used.
AuthorizationHelper.cs
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AuthorizationHelper
{
public class AuthorizationHelper
{
const string aadTenant = "https://login.windows.net/<your-tenant>";
public const string aadResource = "https://<yourAOS>.cloudax.dynamics.com";
const string aadClientAppId = "<client id>";
const string aadClientAppSecret = "<client secret>";
/// <summary>
/// Retrieves an authentication header from the service.
/// </summary>
/// <returns>The authentication header for the Web API call.</returns>
public static string GetAuthenticationHeader()
{
AuthenticationContext authenticationContext = new AuthenticationContext(aadTenant);
AuthenticationResult authenticationResult;
var creadential = new ClientCredential(aadClientAppId, aadClientAppSecret);
authenticationResult = authenticationContext.AcquireTokenAsync(aadResource, creadential).Result;
// Create and get JWT token
return authenticationResult.CreateAuthorizationHeader();
}
}
}
Program.cs
using ODataClient.Microsoft.Dynamics.DataEntities;
using System;
namespace DataPackageHandler
{
using AuthorizationHelper;
using Microsoft.OData.Client;
class Program
{
static void Main(string[] args)
{
string ODataEntityPath = AuthorizationHelper.aadResource + "/data";
Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute);
var d365Client = new Resources(oDataUri);
d365Client.SendingRequest2 += new EventHandler<SendingRequest2EventArgs>(delegate (object sender, SendingRequest2EventArgs e)
{
var authenticationHeader = AuthorizationHelper.GetAuthenticationHeader();
e.RequestMessage.SetHeader("Authorization", authenticationHeader);
});
PackageImporter.ImportPackage(d365Client, #"..\debug\SampleData\usmf_asset-major-types-01.zip");
PackageExporter.ExportPackage(d365Client, #"..\debug\SampleData\");
Console.WriteLine("Press enter to exit...");
Console.ReadLine();
}
}
}

Trying to establish a connection in xamarin VS 2019

I’m trying to establish a connection with a Web Service already running with Visual Studio 2019 community. The connection is already establish on Visual Studio but when trying to use it I got CS0119 error ‘UsuariosSoap’ is a type, which is not valid int given context.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using System.Net;
using UsuarioWS;
namespace XamarinWSMobile
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void AnadirUsuario(object sender, EventArgs e)
{
//establece la conexion con el web service
UsuarioWS.UsuariosSoap usuarioWS = UsuarioWS.UsuariosSoap;
usuarioWS.GuardarUsuarioAsync(this.Nombre.Text, this.Apellidos.Text,this.Direccion.Text, this.Pueblo.Text, this.ZipCode.Text, this.FechaNac.Text);
}
}
}
That error is telling UsuariosSoap is a Type so this is wrong:
UsuarioWS.UsuariosSoap usuarioWS = UsuarioWS.UsuariosSoap;
In order to use it, you need to create an instance of the service, the UsuariosSoap class, before using it.
Replace the line above with this:
UsuarioWS.UsuariosSoap usuarioWS = new UsuarioWS.UsuariosSoap();
Hope this helps.-

Converting Request.RequestUri to ASP.NET Core 2.1

What is the ASP.NET Core MVC equivalent to Request.RequestURI?
I am trying to set up an ASP.NET Core implementation of JSGrid. The example provided they provide is pre-Core so I am having some problems converting the source code to ASP.NET Core.
Getting stuck on converting one last error on Request.RequestUri.Query
I read this post but couldn't figure out how it applied to my case and it's also 3 years old. I'm hoping that Microsoft has provided a new using which will handle RequestUri by now but I can't seem to find it.
Here's my controller so far.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Deviation.Data;
using System.Collections.Specialized;
using System.Web;
namespace Deviation.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class JSGridController : ControllerBase
{
private readonly DeviationContext _context;
public JSGridController(DeviationContext context)
{
_context = context;
}
public IEnumerable<object> Get()
{
ClientFilter filter = GetFilter();
var result = _context.MissedDeliveries.Where(c =>
(String.IsNullOrEmpty(filter.Delivery) || c.Delivery.Contains(filter.Delivery))
);
return result.ToArray();
}
private ClientFilter GetFilter()
{
NameValueCollection filter = HttpUtility.ParseQueryString(Request.RequestUri.Query);
return new ClientFilter
{
Delivery = filter["Delivery"],
};
}
}
}
Many thanks to anyone who could provide a bit of guidance.
Try HttpContext.Request.Query :
var q = HttpContext.Request.Query;
var deliveries = q["Delivery"];
var delivery = q["Myquery"].FirstOrDefault();

Accessing Office Clip Board using C#.net

I use Visual Studio 2005 to develop a "Windows Service" using c#.net. My code requires to access the MS office Clipboard. But on trying to access the Clipboard class, the debugger throws an error
"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it."
during the run-time. On checking for the solutions, I found that this could be solved by adding "[STAThread]" before the main method. But on adding this, I get a compilation error
"The type or namespace name 'STAThread' could not be found (are you missing a using directive or an assembly reference?)"
Is it possible to access the clipboard with my current version of .NET(.NET 3.0)?
The main method is in a file titled "program.cs" and the logic is in a file titled "Service.cs". Clipboard is used by Service.cs.
/* Program.cs */
using System.Collections.Generic;
using System.ServiceProcess;
using System.Text;
using System.Media;
using System.Threading;
namespace WindowsService1
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
#if DEBUG
Service1 serv = new Service1();
serv.onDebug();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
#else
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new Service1() };
ServiceBase.Run(ServicesToRun);
#endif
}
}
}
/* Service.cs */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Timers;
namespace WindowsService1
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
public void onDebug()
{
OnStart(null);
}
protected override void OnStart(string[] args)
{
clear_cb();
}
protected void clear_cb()
{
Clipboard.Clear(); // This is the line where I get the exception
}
protected override void OnStop()
{
// TODO: To clear the back up Database
}
}
}

name 'application' does not exist in the current context

Hi I'm working to develop a solution to creating a toolbar in Outlook 2010 using VSTO 2012 and the microsoft outlook 2010 addin. In a nutshell I am able to create the Outlook ribbon and a button but I am unable to get the button to open an .oft file. In Visual Studio I get the following error "The name 'application' does not exist in the current context". I have added a reference to the Microsoft Office 14.0 Object Library also. Below is the code...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Ribbon;
namespace OutlookAddIn8
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void CreateItemFromTemplate()
{
Outlook.Folder folder =
Application.Session.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
Outlook.MailItem mail =
Application.CreateItemFromTemplate(
#"c:\ivy.oft", folder) as Outlook.MailItem;
mail.Subject = "Congratulations";
mail.Save();
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
}
}
}
Thanks any help is appreciated it is probably something simple thats been missed.
An instance of Application can be accessed using Globals.ThisAddIn.Application. If you renamed your AddIn class to something different e.g. MyAddIn then the command will be: Globals.MyAddIn.Application.
Here is a link with more details: http://msdn.microsoft.com/en-us/library/vstudio/bb157876(v=vs.100).aspx
Finally got there in the end, heres the code.....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace OutlookAddIn3
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Outlook.Application Application = Globals.ThisAddIn.Application;
Outlook.MailItem mail =
Application.CreateItemFromTemplate(
#"Z:\Transfer\Outlook 2010 Templates\testsubject.oft") as Outlook.MailItem;
mail.Display(true);
}

Resources