User98
User98

Reputation: 29

Win32Exception: The system cannot find the file specified

I am trying to open a database (present in localhost) written in SQLite in a .NET web service which performs the login functionality. The database has a table called user from which I wish to access the username and password. I am using SqlDataAdapter and SQLDataSource for this purpose for accessing the username and password. But when I run the login webservice, I get this error:

Message=A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Source=.Net SqlClient Data Provider

Inner Exception 1:

Win32Exception: The system cannot find the file specified

The error is showing up though I have placed the database file inside the bin folder. Visual Studio is pointing to this line:

da.Fill(ds);

WebService.cs:

namespace loginwebservice
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.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 DataSet login(string uname, string pwd)
    {
        SqlDataAdapter da = new SqlDataAdapter("select * from user where user_name = '" + uname + "' and user_password='" + pwd + "' ;",
        @"Data Source=localhost;Initial Catalog=EMP;Integrated Security=True");
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;
    }
}
}

The connection string specified in Web.Debug.Config is:

<connectionStrings>
  <add name="UserDataManager" 
    connectionString="Data Source=localhost;Integrated Security=True" 
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

How do I get past this error and access the database?

Upvotes: 0

Views: 6063

Answers (2)

shami sheikh
shami sheikh

Reputation: 562

You can try this.

 namespace loginwebservice
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.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
    {
        string cn = ConfigurationManager.ConnectionStrings["UserDataManager"].ConnectionString;
        SQLiteConnection con = new SQLiteConnection(cn)
        [WebMethod]
        public DataSet login(string uname, string pwd)
        {
            SQLiteDataAdapter da = new SQLiteDataAdapter("select * from user where user_name = '" + uname + "' and user_password='" + pwd + "' ;",con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds;
        }
    }
}

<connectionStrings>
  <add name="UserDataManager" 
    connectionString="Data Source=localhost; Initial Catalog=EMP; Integrated 
    Security=True" 
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

Upvotes: 0

D-Shih
D-Shih

Reputation: 46249

You want to use SQLite DB, you can't use SqlDataAdapter class.

SqlDataAdapter class is for connection with SQLServer

Here is a link talk about SQLLite in C#

If you use this Libary. here is some sample code for you.

SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=localhost;Initial Catalog=EMP;Integrated Security=True");
m_dbConnection.Open();
SQLiteDataAdapter myAdapter = new SQLiteDataAdapter("select * from user where user_name = '" + uname + "' and user_password='" + pwd + "' ;", m_dbConnection);
DataSet ds = new DataSet();
myAdapter.Fill(ds);
m_dbConnection.Close();

Upvotes: 1

Related Questions