0


I created an ASP.Net 4.0 website and make an OLEDB connection with Visual Foxpro 8.0 databse for selecting data from a table. Used code is written below...

    string strConnString = "Provider=vfpoledb;Data Source=C:\Users\mohammads\Documents\Visual FoxPro Projects\dbTallowMaster.dbc;";
    OleDbConnection connection = new OleDbConnection(strConnString);
    connection.Open();
    string username = "675";
    string password = "675";
    string sqlQuery = "SELECT userinfoid, username, password FROM tm_userinfo.dbf WHERE username = \"" + username + "\" AND password = \"" + password + "\"";
    OleDbCommand cmd = new OleDbCommand(sqlQuery, connection);
    OleDbDataAdapter oOleDbDataAdapter = new OleDbDataAdapter(cmd);
    DataTable dt = new DataTable();
    oOleDbDataAdapter.Fill(dt);

this code is working fine in local system but when I hosted this site on Windows 7 IIS 6.0 then connection doesn't open and I get error that "invalid path or file name". Please suggest me why this code creates problem only when I host it in IIS.

Is there should be some change in datasource of connection string while hosting site in IIS.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Shoeb
  • 652
  • 9
  • 17

1 Answers1

2

A side-note... I would start building your queries using parameterized, especially if coming from the web. VFP uses "?" as a place-holder for parameters so you don't have to explictily wrap the values in quotes.

string sqlQuery = "SELECT userinfoid, username, password "
    + "FROM tm_userinfo.dbf "
    + "WHERE username = ? and password = ?";
OleDbCommand cmd = new OleDbCommand(sqlQuery, connection);
cmd.Parameters.Add("parmUserName", OleDbType.Char).Value = username; // from your string
cmd.Parameters.Add("parmPassword", OleDbType.Char).Value = password; // variables...

OleDbDataAdapter oOleDbDataAdapter = new OleDbDataAdapter(cmd);

Notice the parameters are added in same sequential order as the "?" in the query.

As for connecting, shouldn't it be

"vfpoledb.1" instead of "vfpoledb" in your connection string.

And finally, a consideration, since your data is in a subfolder under "Users", they are typically "restricted" to that user. When running IIS, the user is typically something like

IUSR_{machine name} representing the internet user, and not YOU. So permissions might be your issue.

DRapp
  • 47,638
  • 12
  • 72
  • 142
  • Thanks DRapp, you are right, there was permission related issue because my database folder was existing in the subfolder's of User. I add a permission everyone and provide full access control and my problem being solved Thanx a lot again.... – Shoeb Jan 04 '13 at 14:11
  • @Shoeb, you are welcome. Also, don't forget, as a newbie, to up-arrow check answers that help you, and also click the CHECKMARK to any solutions that SOLVE your solution. This way, others looking for similar problems know what worked and could help them too. – DRapp Jan 04 '13 at 14:22
  • I clicked on checkMark answer as well as clicked on up-arrow. thanx – Shoeb Jan 04 '13 at 15:39