473,395 Members | 1,766 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,395 software developers and data experts.

WebService cant access Postgre database

Sakalicek
Hi all, could you please help me with my big problem?

I have WebService on IIS. This WebService has methods to control database stored on server.
I am using Postgre database and to access to database I have Npgsql.dll library.
This library is stored in GAC (global assembly cache).

The WebService is not able to open the connection to the database even the connection string is allright, everything seems to be OK. But when the function Open() is called, there occurs an errror "Object reference not set to instance of object" or something like this.

Although, if I access the database with some console application, everything goes well.
Just the bloody WebService :(

Thank you very much for any help.
Zdenek Mach.

ICQ# 173965423
skype: Zdenek_Mach
Mar 21 '07 #1
14 4656
kenobewan
4,871 Expert 4TB
Welcome to the site. I assume that the problem is in the web service and not IIS. So the question is, what object reference is not set?
Mar 21 '07 #2
I downloaded source code for Npgsql.dll and debug it.
The problem lies in section where sockets are made:

Socket socket = new Socket(AddressFamily.InterNetwork,SocketType.Strea m,ProtocolType.Tcp);

IAsyncResult result = socket.BeginConnect(new IPEndPoint(ResolveIPHost(context.Host), context.Port), null, null);

I thought about it and it seems to me that the problem could be in setting of WebService account.
Is it right that if I debug WebService, it all runs under some other account than localhost?
I think it would be somewhere here in all of these accounts and permissions.

Am I right?Tell me please :D
Thx, Zdenek.
Mar 21 '07 #3
kenobewan
4,871 Expert 4TB
You receive the error when you open try to open the connection, so what information do you have that its to do with sockets? Are you able to test the connection and the sockets separately?
Mar 23 '07 #4
I have found it from source of Npgsql.dll library. I step into Open() function and further found that it ends when there is invokes a method socket.BeginConnect() or something like this.
Thus I think that if I debug my Web Service, "I have no permimssions to create sockets".

Do yoy understand what I am trying to say?
Z.
Mar 26 '07 #5
I also tried to create simple web service and console application and simple create socket and call BeginConnection on it.
Console application works well but WebService ended with same exception "Object reference not set to instance of object".
So thereby I think it would be just in debugger permissions.

Tell me, am I wrong?
Z.
Mar 26 '07 #6
kenobewan
4,871 Expert 4TB
Maybe an example will help:
ASP.NET Web Service
Mar 27 '07 #7
Sorry but this wouldnt help me.
Mar 27 '07 #8
Atli
5,058 Expert 4TB
The problem is not that you dont have permission. If that would be the case it would throw some permission exception, not a null reference exception.

As the error say's. Some object that your code is trying to access is set to null.
My guess would be the object you are calling the Open() method on.

Could you perhaps show us the code that gives you the error?
Mar 27 '07 #9
Yes, it could be.
This object may be the Npgsql.dll library which I have in GAC.
I have method to open connection to Postgre database:

private void Open()
{
// open connection
if (_conDatabase == null)
{
_conDatabase = new NpgsqlConnection(_sConnectionString);
_conDatabase.Open();
}
}
Then there is just code from Npgsql.dll and on the end there is

Socket socket = new Socket(AddressFamily.InterNetwork,SocketType.Strea m,ProtocolType.Tcp);

IAsyncResult result = socket.BeginConnect(new IPEndPoint(ResolveIPHost(context.Host), context.Port), null, null);

And then exception occurs.
Do you think that it could be in Npgsql.dll in my GAC?
Or could I add this dll to GAC in some wrong way or what?

Thx a lot for any help, Zdenek.
Mar 27 '07 #10
So what?
Do you have some idea?
The exception I got is "The attempted operation was not supported for the type of object referenced".

Zdenek.
Mar 28 '07 #11
Atli
5,058 Expert 4TB
I think it could be your if statment.
It could be that the _conDatabase object cant be null, or that the parser throws the null exception when your checking it.

So I'd try using a try block
Somewhat like this
Expand|Select|Wrap|Line Numbers
  1. private bool Open()
  2. {
  3.   try{
  4.     _conDatabase.Open();
  5.     return true;
  6.   } 
  7.   catch(Exception) {
  8.     try {
  9.       _conDatabase = new NpgsqlConnection(_sConnectionString);
  10.       _conDatabase.Open();
  11.       return true;
  12.     } 
  13.     catch(Exception) {
  14.       // Fatal error
  15.       return false;
  16.     }
  17.   }
  18. }
  19.  
This method will also return false on faliure so your app can handle it rather than having your program crash cause of it.
Mar 28 '07 #12
I think it would not help me, but I will try it tomorrow morning.

But didnt mention that my colleague tried it on his PC and it worked well.
Connection was opened...

Thereby I think it could be in some permissions or ASPNET account permissions.
I read lot of about it but I am not able to solve this.

Quite desperate, Zdenek.
Mar 28 '07 #13
Sorry that I am answering too late.
I have found that problem was in my IIS.
It was broken or something, so I have to reinstall OS and than install IIS again.
Now its working well.
Jul 4 '07 #14
I am doing connectivity to PostgreSql from asp.net 2.0 using odbc but i am not able to connect i got error Data source name not found and no default driver specified.

code is written for connectivity is like...

con = new OdbcConnection("Driver={PostgreSQL};Server=Ip Address;Port=5432;Database=database name;Uid=user id;Pwd=;");

from google i found its alternative npgsql but i dont know why,i am not able to download npgsql.dll...true is i am not able to find that dll from internet...

please help me...how i can download dll for npgsql....please provide me source i need it very much....


i am very thankful to u in advance.
Jan 25 '08 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Nicolae Fieraru | last post by:
Hi All, I am working on a web site in asp which will be hosted on a Windows 2003 server. I use the following code to connect to the database: Set objConn =...
13
by: Zlatko Matić | last post by:
Is it possible to use Access as front-end for POstgreSQL and how ? What about Access Projects (.adp) and PostgreSQL ?
3
by: Trygve Lorentzen | last post by:
Hi, I don't know if this is a stupid question, but I observe that my webservice is created for each call to a webmethod. More precisely an instance of the webservice class is created for each...
6
by: kenneth fleckenstein nielsen | last post by:
Hi guru's It runs ok on my developmaschine, and on the test server that i've set up. but fails after installing on the customers server. I made a XML webservice that does these steps: a) access a...
1
by: kamig | last post by:
Hey! guys i have this annoying question i have upgrade my webService project from visual studion.NET 2003 to 2005 but the problem is tht i cant access my webService directly from iis mmc by click...
3
Sakalicek
by: Sakalicek | last post by:
Hi all, can you please help me? I have Web Service that should do some things on Postgre database. I am using Npgsql.dll to provide functions to make connection to the database. But I am not...
1
by: nilart | last post by:
Hi, I have an installer application (Installshield) which installs postgre DB programmatically on windows: I have a requirement where postgre DB is expected work after upgrading OS from windows XP...
5
by: prajiv | last post by:
Hi, Pls guide me in synchronizing data from PostGre to Cache. i.e if we update in one database the other database must automatically get updated.I dont want to use the Tool ,I need the code for it...
0
by: freeskier | last post by:
Hello, Sorry for the newb question; I've spent a good amount of time trying to figure this out. I am fairly new to the Postgre world. I am currently in the process of upsizing several MS Access...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.