首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Win32Exception:系统找不到指定的文件

Win32Exception:系统找不到指定的文件
EN

Stack Overflow用户
提问于 2018-07-10 11:37:01
回答 2查看 4.1K关注 0票数 0

我试图在一个执行登录功能的SQLite web服务中打开一个用.NET编写的数据库(在本地主机中)。数据库有一个名为user的表,我希望从该表访问用户名和密码。为此,我使用SqlDataAdapter和SQLDataSource访问用户名和密码。但是,当我运行登录get服务时,我会得到以下错误:

在建立到Server的连接时,发生了与Message=A网络相关或特定于实例的错误。找不到或无法访问服务器。验证实例名是否正确,以及Server是否配置为允许远程连接。(提供者:命名管道提供程序,错误: 40 -无法打开到Server的连接) Source=.Net SqlClient数据提供程序 内部例外1: Win32Exception:系统找不到指定的文件

虽然我已将数据库文件放置在bin文件夹中,但仍会出现错误。Visual指向这一行:

代码语言:javascript
复制
da.Fill(ds);

WebService.cs:

代码语言:javascript
复制
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;
    }
}
}

Web.Debug.Config中指定的连接字符串是:

代码语言:javascript
复制
<connectionStrings>
  <add name="UserDataManager" 
    connectionString="Data Source=localhost;Integrated Security=True" 
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

如何克服此错误并访问数据库?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-07-10 11:51:57

你可以试试这个。

代码语言:javascript
复制
 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;
        }
    }
}

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

票数 0
EN

Stack Overflow用户

发布于 2018-07-10 11:53:11

要使用SQLite DB,就不能使用SqlDataAdapter类。

SqlDataAdapter类用于与SQLServer的连接

下面是关于SQLLite in C#的链接

如果你用这个Libary。这是一些给你的示例代码。

代码语言:javascript
复制
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();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51264207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档