472,331 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 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 4242
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...
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...
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...
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:...
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 :...
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...
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...
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...
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...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.