I have built a little web application that checks a field on an oracle database then redirect users depending on this value. I have just managed to deploy the admin are with a sql databse and thought all was well, but this is key to the functionality of
the site.
In my admin area I had to change the connection string for the sqlserverclient as the provider to make the site work, but I'm not sure what to do with the oracle bit.
To explain how this works, basically I am using System.Data.Odbc in a model. This model contains the connection string and basically when called, performs the query on the oracle table and returns bool to the controller. The controller then directs the user
to the correct view.
This works fine when debugging on my machine but when I deploy the value is always to the defual "false" despite me changing the value on the oracle table so it would return true.
Below is the model itself, I have also correctly setup the ODBC settings on the server and they connect to the database.
I can't think what else it could be so I am guessing it is something to do with the connection string needing to be in the database?
Any way here is my model:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Odbc;
namespace Gateway.Models
{
public static class Lock
{
static OdbcConnection conn = new OdbcConnection();
static OdbcDataAdapter da = new OdbcDataAdapter();
static DataSet ds = new DataSet();
static Boolean bol = false;
static string val;
public static bool getState()
{
string strSQL = "SELECT TABLE.FIELD_LOCK.* FROM TABLE.FIELD_LOCK";
goget(strSQL);
if (bol == true)
{
val = ds.Tables[0].Rows[0][0].ToString();
if (val == "Y")
return true;
return false;
}
else
{
return false;
}
}
static void Conect()
{
conn.ConnectionString = "DSN=database;UID=user;PWD=password;DBQ=database;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;MDI=F;CSR=F;FWC=F;PFC=10;TLO=0;";
}
public static void goget(string strSQL)
{
try
{
Conect();
da.SelectCommand = new OdbcCommand(strSQL);
da.SelectCommand.Connection = conn;
ds.Tables.Clear();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
bol = true;
}
}
catch // Unanticipated error.
{
bol = false;
}
}
Hello,It seems that you wanna change the connection string dynamically……So please do to use the connection string by putting it into the web.config's <connectionStrings> tags by adding a name,and then use ConfiguationManager.ConnectionStrings["name defined
in the connection string's tag"].ConnectionString to read it out。
mcinnes01
Member
16 Points
121 Posts
Oracle connection string help
May 04, 2012 02:27 PM|LINK
Hi,
I have built a little web application that checks a field on an oracle database then redirect users depending on this value. I have just managed to deploy the admin are with a sql databse and thought all was well, but this is key to the functionality of the site.
In my admin area I had to change the connection string for the sqlserverclient as the provider to make the site work, but I'm not sure what to do with the oracle bit.
To explain how this works, basically I am using System.Data.Odbc in a model. This model contains the connection string and basically when called, performs the query on the oracle table and returns bool to the controller. The controller then directs the user to the correct view.
This works fine when debugging on my machine but when I deploy the value is always to the defual "false" despite me changing the value on the oracle table so it would return true.
Below is the model itself, I have also correctly setup the ODBC settings on the server and they connect to the database.
I can't think what else it could be so I am guessing it is something to do with the connection string needing to be in the database?
Any way here is my model:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Data.Odbc; namespace Gateway.Models { public static class Lock { static OdbcConnection conn = new OdbcConnection(); static OdbcDataAdapter da = new OdbcDataAdapter(); static DataSet ds = new DataSet(); static Boolean bol = false; static string val; public static bool getState() { string strSQL = "SELECT TABLE.FIELD_LOCK.* FROM TABLE.FIELD_LOCK"; goget(strSQL); if (bol == true) { val = ds.Tables[0].Rows[0][0].ToString(); if (val == "Y") return true; return false; } else { return false; } } static void Conect() { conn.ConnectionString = "DSN=database;UID=user;PWD=password;DBQ=database;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;MDI=F;CSR=F;FWC=F;PFC=10;TLO=0;"; } public static void goget(string strSQL) { try { Conect(); da.SelectCommand = new OdbcCommand(strSQL); da.SelectCommand.Connection = conn; ds.Tables.Clear(); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { bol = true; } } catch // Unanticipated error. { bol = false; } }Thanks in advance,
Andy
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Oracle connection string help
May 06, 2012 01:35 AM|LINK
Hello,It seems that you wanna change the connection string dynamically……So please do to use the connection string by putting it into the web.config's <connectionStrings> tags by adding a name,and then use ConfiguationManager.ConnectionStrings["name defined in the connection string's tag"].ConnectionString to read it out。
For more about ConfigurationManager's usage,please refer to this:http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager(v=vs.80).aspx
Reguards!