can't see this odbc datasource on the network from a web service

C

cj2

This code works:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.Odbc;

namespace CWebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, using
ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{

[WebMethod()]
public string CashOnly(string act)
{
DataSet ds = new DataSet();
OdbcConnection myOdbcConnection = new
OdbcConnection("Driver={Microsoft Visual FoxPro Driver};"
+ "SourceType=DBF;"
+ "SourceDB=c:;"
+ "Exclusive=No;"
+ "Collate=Machine;"
+ "NULL=NO;"
+ "DELETED=NO;"
+ "BACKGROUNDFETCH=NO");

OdbcCommand myOdbcCommand = new OdbcCommand("select flag
from d:\\act_frau.DBF where act = '" + act.Trim() + "'", myOdbcConnection);
myOdbcConnection.Open();
string results = myOdbcCommand.ExecuteScalar().ToString();
myOdbcConnection.Close();

return results;

}
}
}


But with the actual production file on the network it doesn't:

OdbcCommand myOdbcCommand = new OdbcCommand("select flag
from \\\\fileserver\\i\\probill\\act_frau.DBF where act = '" +
act.Trim() + "'", myOdbcConnection);

It gives me:

System.Data.Odbc.OdbcException: ERROR [42S02] [Microsoft][ODBC Visual
FoxPro Driver]File 'act_frau.dbf' does not exist.

The file does exist. FYI, i is a directory not a drive letter.

I've also tried this web service in VB and it works:

Dim myOdbcCommand As New OdbcCommand("select flag from
\\fileserver\i\probill\act_frau.dbf where act = '" + act.Trim + "'",
myOdbcConnection)

What am I doing wrong?
 
S

Steven Cheng [MSFT]

Hi Cj,

From your description, you're trying to connect a VFP database in an
ASP.NET webservice, you used the ODBC driver. However, you found that the
code didn't work in webservice(from a network place) while worked for a
database file on local disk, correct?

I've also discussed this with some other database engineer. They suggest
you check the following things:

1.Make sure there hasn't any other program or person that has opened the
vfp database before your code accesss it. That'll possibly cause the
database not found error.

2. In the code, the only difference is the string escaping for the back
slash. I suggest you try using the following style code in C3 to see
whether it works:

OdbcCommand myOdbcCommand = new OdbcCommand(@"select flag from
\\fileserver\i\probill\act_frau.DBF where act = '" + act.Trim() + "'",
myOdbcConnection);

Btw, regarding on the network place, have you tried performing some other
simple remote resource accessing , such as try accessing a file via
System.IO API on that server to see whether you'll get similar error? If
so, that may indicate some network resource accessing issue.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
Date: Wed, 02 Jul 2008 10:42:06 -0400
From: cj2 <[email protected]>
User-Agent: Thunderbird 2.0.0.14 (Windows/20080421)
MIME-Version: 1.0
Subject: can't see this odbc datasource on the network from a web service
This code works:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.Odbc;

namespace CWebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, using
ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{

[WebMethod()]
public string CashOnly(string act)
{
DataSet ds = new DataSet();
OdbcConnection myOdbcConnection = new
OdbcConnection("Driver={Microsoft Visual FoxPro Driver};"
+ "SourceType=DBF;"
+ "SourceDB=c:;"
+ "Exclusive=No;"
+ "Collate=Machine;"
+ "NULL=NO;"
+ "DELETED=NO;"
+ "BACKGROUNDFETCH=NO");

OdbcCommand myOdbcCommand = new OdbcCommand("select flag
from d:\\act_frau.DBF where act = '" + act.Trim() + "'", myOdbcConnection);
myOdbcConnection.Open();
string results = myOdbcCommand.ExecuteScalar().ToString();
myOdbcConnection.Close();

return results;

}
}
}


But with the actual production file on the network it doesn't:

OdbcCommand myOdbcCommand = new OdbcCommand("select flag
from \\\\fileserver\\i\\probill\\act_frau.DBF where act = '" +
act.Trim() + "'", myOdbcConnection);

It gives me:

System.Data.Odbc.OdbcException: ERROR [42S02] [Microsoft][ODBC Visual
FoxPro Driver]File 'act_frau.dbf' does not exist.

The file does exist. FYI, i is a directory not a drive letter.

I've also tried this web service in VB and it works:

Dim myOdbcCommand As New OdbcCommand("select flag from
\\fileserver\i\probill\act_frau.dbf where act = '" + act.Trim + "'",
myOdbcConnection)

What am I doing wrong?
 
C

cj2

I had a small breakthrough today. I found when I run the web service
from within Visual Studio by doing debug start it works! Unfortunately
when I publish it to local host it doesn't. Why do you think that would
be the case?

OdbcCommand myOdbcCommand = new OdbcCommand("select flag from
\\\\fileserver\\i\\probill\\act_frau.DBF where act = '" + act.Trim() +
"'", myOdbcConnection);

Hi Cj,

From your description, you're trying to connect a VFP database in an
ASP.NET webservice, you used the ODBC driver. However, you found that the
code didn't work in webservice(from a network place) while worked for a
database file on local disk, correct?

I've also discussed this with some other database engineer. They suggest
you check the following things:

1.Make sure there hasn't any other program or person that has opened the
vfp database before your code accesss it. That'll possibly cause the
database not found error.

2. In the code, the only difference is the string escaping for the back
slash. I suggest you try using the following style code in C3 to see
whether it works:

OdbcCommand myOdbcCommand = new OdbcCommand(@"select flag from
\\fileserver\i\probill\act_frau.DBF where act = '" + act.Trim() + "'",
myOdbcConnection);

Btw, regarding on the network place, have you tried performing some other
simple remote resource accessing , such as try accessing a file via
System.IO API on that server to see whether you'll get similar error? If
so, that may indicate some network resource accessing issue.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
Date: Wed, 02 Jul 2008 10:42:06 -0400
From: cj2 <[email protected]>
User-Agent: Thunderbird 2.0.0.14 (Windows/20080421)
MIME-Version: 1.0
Subject: can't see this odbc datasource on the network from a web service
This code works:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.Odbc;

namespace CWebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, using
ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{

[WebMethod()]
public string CashOnly(string act)
{
DataSet ds = new DataSet();
OdbcConnection myOdbcConnection = new
OdbcConnection("Driver={Microsoft Visual FoxPro Driver};"
+ "SourceType=DBF;"
+ "SourceDB=c:;"
+ "Exclusive=No;"
+ "Collate=Machine;"
+ "NULL=NO;"
+ "DELETED=NO;"
+ "BACKGROUNDFETCH=NO");

OdbcCommand myOdbcCommand = new OdbcCommand("select flag
from d:\\act_frau.DBF where act = '" + act.Trim() + "'", myOdbcConnection);
myOdbcConnection.Open();
string results = myOdbcCommand.ExecuteScalar().ToString();
myOdbcConnection.Close();

return results;

}
}
}


But with the actual production file on the network it doesn't:

OdbcCommand myOdbcCommand = new OdbcCommand("select flag
from \\\\fileserver\\i\\probill\\act_frau.DBF where act = '" +
act.Trim() + "'", myOdbcConnection);

It gives me:

System.Data.Odbc.OdbcException: ERROR [42S02] [Microsoft][ODBC Visual
FoxPro Driver]File 'act_frau.dbf' does not exist.

The file does exist. FYI, i is a directory not a drive letter.

I've also tried this web service in VB and it works:

Dim myOdbcCommand As New OdbcCommand("select flag from
\\fileserver\i\probill\act_frau.dbf where act = '" + act.Trim + "'",
myOdbcConnection)

What am I doing wrong?
 
S

Steven Cheng [MSFT]

Thanks for your reply Cj,

I think the further information you mentioned is quite important. That make
me think that the issue is probably due to the application's execution
context(user account).

For ASP.NET web application/webservice which run via Visual Studio built-in
server, since the built-in server is winform application, your web app code
is actually running under your current logon user account(under which the
visual studio also runs).

However, if you deployed it into IIS,(suppose you're using IIS6 on win2k3
or iis7 on vista), by default the web app is running under the IIS worker
process account( e.g the Network Service for IIS6 app pool).

Therefore, I suggest you first focus on this. For example, you can try
changing your IIS worker process account(app pool account) to an
interactive user account to see whether it works. Or you can
programmtically impersonate as a certain interactive user account at the
code you call the ODBC database.

For impersonate, you can refer to the following articles:

#How To: Use Impersonation and Delegation in ASP.NET 2.0
http://msdn.microsoft.com/en-us/library/ms998351.aspx

http://support.microsoft.com/kb/306158

If there is anything unclear or any other findings, please feel free to let
me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
C

cj2

That's it. I don't know why I missed that. I had impersonation set up
in the Web.config files of my VB ASP.net programs but totally forgot it
when creating this C# program.

Thanks,
CJ
 
S

Steven Cheng [MSFT]

Thanks for your followup CJ,

I'm glad that you've figured out the problem.

Have a good day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top