Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Database Connection Errors with VB.NET

335359May 4 2005 — edited Jul 26 2005
I have a piece of code that I did both in C# and VB.NET and what is driving me crazy is the C# version works just fine and the VB.NET version does not.

Here is the error I am getting in VB.NET
Exception Details: Oracle.DataAccess.Client.OracleException: ORA-12154: TNS:could not resolve

I am running 9i, XPSP2, and 1.1 of the framework.

As well I am including the code for both.

C# version:
public static readonly string CONN_STRING = ConfigurationSettings.AppSettings["OracleConnectionString"];

I have these keys in my web.config:
<appSettings>
<add key="OracleConnectionString" value="User ID=myid;Password=mypass;Data Source=portal" />
<add key="SqlConnectionString" value="server=localhost;Trusted_Connection=true;database=Northwind" />
</appSettings>

private void Button1_Click(object sender, System.EventArgs e)
{
OracleConnection dbConn = new OracleConnection(CONN_STRING);
dbConn.Open();

OracleCommand cmd = new OracleCommand("",dbConn);
cmd.CommandText = "ASPAllianceArticles.Article643.OpenXmlFile";
cmd.CommandType = CommandType.StoredProcedure;

OracleParameter dirParam = new OracleParameter("p_dir_name", OracleDbType.Varchar2);
//cmd.Parameters.Add(new OracleParameter("p_dir_name", OracleDbType.Varchar2)).Value = "C:\\xmldata";

//dirParam.Direction = ParameterDirection.Input;
dirParam.Value = "C:\\xmldata";
cmd.Parameters.Add(dirParam);

try
{
cmd.ExecuteNonQuery();
StatusLabel.Visible = true;
StatusLabel.Text = "XML Generation Successful";
}
catch (Exception ex)
{
StatusLabel.Visible = true;
StatusLabel.Text = "<b>ERROR</b>: " + ex.Message.ToString();
}
finally
{
dbConn.Dispose();
}
BindXmlDataGrid();
}

VB version:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim dbConn As New OracleConnection("Data Source=portal;User ID=myid; Password=mypass;")
dbConn.Open()

Dim cmd As New OracleCommand("", dbConn)
cmd.CommandType() = CommandType.StoredProcedure
cmd.CommandText() = "ASPAllianceArticles.Article643.OpenXmlFile"

Dim param As New OracleParameter("p_dir_name", OracleDbType.Varchar2)
param.Value = "C:\\xmldata"

cmd.Parameters.Add(param)

Try
cmd.ExecuteNonQuery()
StatusLabel.Visible = True
StatusLabel.Text = "XML Generation Successful"
BindXmlDataGrid()
Catch ex As Exception
StatusLabel.Visible = True
StatusLabel.Text = "<b>ERROR</b>: " + ex.Message.ToString()
Finally
dbConn.Dispose()
End Try
End Sub

I am pulling my hair out over this and not sure what else to do. I would appreciate any ideas and help on this matter.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 23 2005
Added on May 4 2005
2 comments
1,062 views