PC Review


Reply
Thread Tools Rate Thread

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

 
 
cj2
Guest
Posts: n/a
 
      2nd Jul 2008
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?
 
Reply With Quote
 
 
 
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      3rd Jul 2008
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 Removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/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 <(E-Mail Removed)>
>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?
>


 
Reply With Quote
 
cj2
Guest
Posts: n/a
 
      3rd Jul 2008
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);


Steven Cheng [MSFT] wrote:
> 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 Removed).
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/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 <(E-Mail Removed)>
>> 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?
>>

>

 
Reply With Quote
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      4th Jul 2008
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 Removed).

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

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>Date: Thu, 03 Jul 2008 14:41:11 -0400
>MIME-Version: 1.0
>Subject: Re: can't see this odbc datasource on the network from a web

service

>
>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);
>
>>>> 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?
>>>

>>

>


 
Reply With Quote
 
cj2
Guest
Posts: n/a
 
      7th Jul 2008
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

Steven Cheng [MSFT] wrote:
> 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 Removed).
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscripti...ult.aspx#notif
> ications.
>
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
> --------------------
>> Date: Thu, 03 Jul 2008 14:41:11 -0400
>> MIME-Version: 1.0
>> Subject: Re: can't see this odbc datasource on the network from a web

> service
>
>> 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);
>>
>>>>> 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?
>>>>

>

 
Reply With Quote
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      8th Jul 2008
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 Removed).

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

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


--------------------
>Date: Mon, 07 Jul 2008 10:58:05 -0400
>From: cj2 <(E-Mail Removed)>
>User-Agent: Thunderbird 2.0.0.14 (Windows/20080421)
>MIME-Version: 1.0
>Subject: Re: can't see this odbc datasource on the network from a web

service

>
>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
>
>Steven Cheng [MSFT] wrote:
>> 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
>>
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating an ODBC datasource Sherwood Windows Vista Administration 1 4th Jun 2008 02:26 PM
ODBC Datasource problems Paul Cheetham Microsoft ASP .NET 4 9th Sep 2007 09:34 AM
Link ODBC Datasource =?Utf-8?B?QmFydGxleQ==?= Microsoft Access 1 3rd Feb 2007 09:35 PM
ODBC Datasource Problems =?Utf-8?B?RWxhbmFoeQ==?= Microsoft Word Document Management 4 25th Jun 2006 07:11 PM
ODBC DataSource Dialog Olo Microsoft ADO .NET 0 22nd Jul 2004 10:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:38 AM.