So i’m really annoyed now.(Still a noob) I’m trying the use my connection string that I created in my “Common” class on my “Logon” form so that i can call a “hhrcv_logon_validation” procedure.
My quesation is how?
I’ve searched everywhere and yes I do get examples but I need someone to explain them better for me please? And maybe some example code as well.
I know I have to create the class for the connection string and the use that connection string to call a proc? Am i right?
This is my code :
using System;
using System.Collections.Generic;
using System.Text;
using CoreLab.Oracle;
namespace WMS
{
class Common
{
static void connect()
{
// Connect
string constr = "User ID=Password;" +
"Password=Username;" +
"Host="ServerName";" +
"Pooling=true;" +
"Min Pool Size=0;" +
"Max Pool Size=100;" +
"Connection Lifetime=0";
OracleConnection con = new OracleConnection(constr);
con.Open();
}
}
Please help!?
So below is what I did with your sample code:
namespace WMS
{
class Common
{
public static string ConnectionString
{
get
{
return ConnectionString;
}
set
{
ConnectionString = "User ID=username;" +
"Password=password;" +
"Host=hostname;" +
"Pooling=true;" +
"Min Pool Size=0;" +
"Max Pool Size=100;" +
"Connection Lifetime=0";
}
}
public static OracleConnection OpenConnection()
{
OracleConnection con = new OracleConnection(ConnectionString);
con.Open();
return con;
}
}
}
Will this work?
And how would I then access it from a form? With this:
<using(var conn = Common.OpenConnection()) {
// use it
}
constrandconare scoped to the method in this example. If you want them to be available outside that, you’ll need to store something in a field. For example, maybe something like:so then you would configure the connection string at some point early in your application:
and then when you need data access:
I should also note that
staticstate isn’t always the best way to do things. It’ll work, but it gives you less options later on.