473,327 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Error accessing Oracle database from a web service

Has anyone had any luck accessing an Oracle database from a web service?

I have a C# DLL with various code to query an Oracle database. If I call
the methods in this DLL from a Windows Forms application everything works
just fine. However, if I call the methods in this DLL from a web service, I
receive the following error when the database connection is opened:

Error: ORA-12154: TNS:could not resolve service name

Does anyone know how to resolve this? It seems strange that it works when
called from a form but fails when called from a web service.

--- Thanks, Jeff
Nov 15 '05 #1
6 4326
Jeff,

By default, ASP.NET runs under a local system account named ASPNET,
which has no access to the network. You are probably failing because of
this. What you have to do is configure the web app so that it runs with the
user credentials of someone who can connect over the network to the
database.

This is why this works in a Windows Forms app, and not in a Web app,
because the user (you) that runs the Windows Forms app has rights to access
the network.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeff" <je**@nowhere.com> wrote in message
news:e5*************@TK2MSFTNGP12.phx.gbl...
Has anyone had any luck accessing an Oracle database from a web service?

I have a C# DLL with various code to query an Oracle database. If I call
the methods in this DLL from a Windows Forms application everything works
just fine. However, if I call the methods in this DLL from a web service, I receive the following error when the database connection is opened:

Error: ORA-12154: TNS:could not resolve service name

Does anyone know how to resolve this? It seems strange that it works when
called from a form but fails when called from a web service.

--- Thanks, Jeff

Nov 15 '05 #2
> By default, ASP.NET runs under a local system account named ASPNET,
which has no access to the network. You are probably failing because of
this. What you have to do is configure the web app so that it runs with the user credentials of someone who can connect over the network to the
database.


Thanks for the info. but I'm afraid that didn't resolve my issue.

The odd thing is that my web service also makes calls to a MS SQL Server
without any problems. The logon information is embedded in the connection
string for both the Oracle connection as well as the MS SQL Server
connection. The only difference is that the MS SQL Server connection works
and the Oracle connection doesn't.

As a test I also added the "ASPNET" user to the "Local Administrators" group
but that had no effect.

Anyone have any other suggestions?

--- Thanks, Jeff
Nov 15 '05 #3
Jeff,

Where is the SQL server located for your web service? Also, what are
the connection strings that you are using for each? You will need to
provide a little more information.

The fact that it runs in a Windows Forms application indicates that it
is a authorization issue of some sort (because the ASPNET application and
Windows Forms applications, if running the same code, differ in the security
context they are using).

Do not add the ASPNET account to the Local Administrators group. You
are just asking for trouble if an anonymous user hacks into the application,
because that user is now elevated to an administrator of the local machine,
and can cause some damage.

I would create a user on the network with limited rights (enough rights
to access the servers you need across the network) and then have the ASP.NET
application impersonate that user.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeff" <je**@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
By default, ASP.NET runs under a local system account named ASPNET,
which has no access to the network. You are probably failing because of
this. What you have to do is configure the web app so that it runs with the
user credentials of someone who can connect over the network to the
database.


Thanks for the info. but I'm afraid that didn't resolve my issue.

The odd thing is that my web service also makes calls to a MS SQL Server
without any problems. The logon information is embedded in the connection
string for both the Oracle connection as well as the MS SQL Server
connection. The only difference is that the MS SQL Server connection

works and the Oracle connection doesn't.

As a test I also added the "ASPNET" user to the "Local Administrators" group but that had no effect.

Anyone have any other suggestions?

--- Thanks, Jeff

Nov 15 '05 #4
See comments in-line below...
Where is the SQL server located for your web service? Also, what are
the connection strings that you are using for each? You will need to
provide a little more information.
The MS SQL Server and Oracle server are both located on separate servers
from my development PC. The connection strings are as follows (watch for
line wrap):

// Oracle connection string (User ID and PWD masked)
oOracleConn.ConnectionString = "Data Source=NESB;User
ID=xxxxxx;Password=xxxxxx";

// MS SQL Server connection string (User ID and PWD masked)
connectionString = "packet size=4096;User ID=xxxxxx;Password=xxxxxx;data
source=\"NNOMA-SQAPP01D\\NNOMASQAPP01D\";persist security info=False;initial
catalog=DailyPlan";
The fact that it runs in a Windows Forms application indicates that it
is a authorization issue of some sort (because the ASPNET application and
Windows Forms applications, if running the same code, differ in the security context they are using).
I would agree; it just seems odd that MS SQL Server doesn't exhibit the same
issue.
Do not add the ASPNET account to the Local Administrators group. You
are just asking for trouble if an anonymous user hacks into the application, because that user is now elevated to an administrator of the local machine, and can cause some damage.
I only did this on my development PC as this is where I am also running IIS
and the web services for development/testing. Being that it didn't work
anyway, I've already removed it from the group.
I would create a user on the network with limited rights (enough rights to access the servers you need across the network) and then have the ASP.NET application impersonate that user.


What's the best (if not only) way to have an ASP.NET application impersonate
a user?

--- Thanks, Jeff
Nov 15 '05 #5
Jeff,

There are two ways to impersonate a user in an ASP.NET application. The
first is with the web.config file. You can place an <identity> tag in the
<web.config> section and set the user that you want the requests to run
under.

The second would be to actually call the LogonUser API and then pass the
handle returned to the static Impersonation method on the WindowsIdentity
class.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeff" <je**@nowhere.com> wrote in message
news:OH*************@TK2MSFTNGP11.phx.gbl...
See comments in-line below...
Where is the SQL server located for your web service? Also, what are the connection strings that you are using for each? You will need to
provide a little more information.
The MS SQL Server and Oracle server are both located on separate servers
from my development PC. The connection strings are as follows (watch for
line wrap):

// Oracle connection string (User ID and PWD masked)
oOracleConn.ConnectionString = "Data Source=NESB;User
ID=xxxxxx;Password=xxxxxx";

// MS SQL Server connection string (User ID and PWD masked)
connectionString = "packet size=4096;User ID=xxxxxx;Password=xxxxxx;data
source=\"NNOMA-SQAPP01D\\NNOMASQAPP01D\";persist security

info=False;initial catalog=DailyPlan";
The fact that it runs in a Windows Forms application indicates that it is a authorization issue of some sort (because the ASPNET application and Windows Forms applications, if running the same code, differ in the security
context they are using).


I would agree; it just seems odd that MS SQL Server doesn't exhibit the

same issue.
Do not add the ASPNET account to the Local Administrators group. You are just asking for trouble if an anonymous user hacks into the application,
because that user is now elevated to an administrator of the local

machine,
and can cause some damage.


I only did this on my development PC as this is where I am also running

IIS and the web services for development/testing. Being that it didn't work
anyway, I've already removed it from the group.
I would create a user on the network with limited rights (enough rights
to access the servers you need across the network) and then have the

ASP.NET
application impersonate that user.


What's the best (if not only) way to have an ASP.NET application

impersonate a user?

--- Thanks, Jeff

Nov 15 '05 #6
> There are two ways to impersonate a user in an ASP.NET application.
The
first is with the web.config file. You can place an <identity> tag in the
<web.config> section and set the user that you want the requests to run
under.


Nicholas,

Thanks, the "identity" tag does the trick. I'm not too keen on placing an
ID/PWD in clear text but I noticed in the docs that you can encrypt the
values and put them in the registry.

Do you know if it's possible to grab a user's Identity from a Windows Forms
application (assuming they're logged onto a Windows NT domain) and somehow
pass that to the web service and use that? Since the users of this
application will be running a Windows Forms app via "no-touch" deployment,
it would be nice if I could just somehow pass their credentials along.

--- Thanks, Jeff
Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Carl | last post by:
Does anyone know what I can do to resolve this problem I have tried everything. I have an identical package and procedure on a different database that works fine. Request Failed...
0
by: Cherrish Vaidiyan | last post by:
hello, Thanx for the suggestions on my Listener query. Now i am performing a simple work.. STANDBY DATABASE creation. I have followed the instraction from Oracle 9i Release 1 documentation...
0
by: Cherrish Vaidiyan | last post by:
sir, The following are the steps that i followed in setting up standby database on Red hat Linux 9. i am using Oracle 9i. i have followed the steps in this site : ...
3
by: Nathan Sokalski | last post by:
When I attempt to run a form created with Oracle9i Forms Builder I receive a dialog box asking for the following info: User Name: Password: Database: I obviously know my User Name and...
1
by: Dave | last post by:
Hi All I'm having a problem connecting to an Oracle database using C# I have a service name : "SN I have a user id :"UID I have a password : "PWD" I can find snippets of code on the web...
10
by: Brian Conway | last post by:
I have no idea what is going on. I have a Login screen where someone types in their login information and this populates a datagrid based off of the login. Works great in debug and test through...
1
by: MAL | last post by:
Hello, I have 2 classes that work great as a windows app to retrieve and process data from an Oracle9i db. When I implement them in a Service program running as Local System, it fails on the...
4
by: alegria4ever | last post by:
I have an Access 2000 database that links several tables from Oracle 9. For some reason or another, one of our user repeatedly gets the following error when accessing queries within this database:...
2
by: khalidanwar123 | last post by:
i am getting the following error while updating a clob field. ERROR java.sql.SQLException: Data size bigger than max size forthis type: 4003 19:28:27,499 ERROR at...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.