c# Winform应用程序中的System.Data.SqlClient.Sql错误

本文关键字:Data SqlClient Sql 错误 System Winform 应用程序 | 更新日期: 2023-09-27 18:02:00

当我尝试在客户端机器上运行我的c# Winform应用程序时,我得到了以下错误

Description:
  Stopped working
Problem signature:
  Problem Event Name:   CLR20r3
  Problem Signature 01: ics.exe
  Problem Signature 02: 1.0.0.0
  Problem Signature 03: 5134926a
  Problem Signature 04: System.Data
  Problem Signature 05: 2.0.0.0
  Problem Signature 06: 4a275e65
  Problem Signature 07: 2755
  Problem Signature 08: 29
  Problem Signature 09: System.Data.SqlClient.Sql
  OS Version:   6.1.7600.2.0.0.768.2
  Locale ID:    1033
Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409
If the online privacy statement is not available, please read our privacy statement     offline:
  C:'Windows'system32'en-US'erofflps.txt

,这是应用程序。运行代码

    [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmLogin2());
        }

这是表单Login Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using ICS.Classes;
using System.Threading;
using Microsoft.Win32;
namespace ICS.Forms
{
    public partial class frmLogin2 : Office2007Form
    {
        static DataAccess da = new DataAccess();
        static DataTable dt = new DataTable();
        int num = 0;
        public frmLogin2()
        {
            Thread t = new Thread(new ThreadStart(SplashScreen));
        t.Start();
        Thread.Sleep(5000);
        InitializeComponent();
        t.Abort();
    }
    void Registries()
    {
        try
        {
            RegistryKey regKey;
            regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE'ICS'POS", true);
            string activated = EncDec.Decrypt(regKey.GetValue("Activated").ToString(), "A!11").ToString();
            if (activated != "TRUE")
            {
                string coder1;
                coder1 = regKey.GetValue("ICSPOS").ToString().Trim();
                num = int.Parse(EncDec.Decrypt(coder1, "A!11"));
                if (num < 30)
                {
                    num++;
                    regKey.SetValue("ICSPOS", EncDec.Encrypt(num.ToString(), "A!11"));
                    lblNum.Text += (30 - num).ToString();
                }
            }
        }
        catch (Exception ex)
        {
            string coder1 = "";
            try
            {
                RegistryKey regKey;
                regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE'ICS'POS", true);
                coder1 = regKey.GetValue("ICSPOS").ToString().Trim();
            }
            catch
            {
            }
            RegistryKey creator;
            creator = Registry.LocalMachine.OpenSubKey("SOFTWARE", true);
            creator.CreateSubKey(@"ICS'POS");
            creator.Close();
            RegistryKey REG2;
            REG2 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE'ICS'POS", true);
            REG2.SetValue("AppName", "POS");
            REG2.SetValue("Version", 1.0);
            REG2.SetValue("Activated", EncDec.Encrypt("No", "A!11"));
            if (string.IsNullOrEmpty(coder1))
            {
                REG2.SetValue("ICSPOS", EncDec.Encrypt("1", "A!11"));
                lblNum.Text += (30 - 1).ToString();
            }
            REG2.Close();
        }
    }
    private void frmLogin2_Load(object sender, EventArgs e)
    {
        try
        {
            ICS_Auth aut = new ICS_Auth();
            Registries();
            //MessageBox.Show(aut.CreatSerial());
            if (num == 1)
            {
                da.ExecuteNonQuery("sp_admin_user");
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
    private void btnLogin_Click(object sender, EventArgs e)
    {
        dt = da.GetDataTable("User_Login", da.CreateSqlParamter("@User_Name", txtUsername.Text)
                                       , da.CreateSqlParamter("@User_Pass", txtUserpass.Text));
        if (dt.Rows.Count == 1)
        {
            //this.Close();
            frmMain main = new frmMain(dt);
            main.Show();
            this.Hide();
        }
        else
        {
            MessageBox.Show("اسم المستخدم او كلمة المرور غير صحيحة");
        }
    }
    private void btnClose_Click(object sender, EventArgs e)
    {
        this.Close();
    }
    public void SplashScreen()
    {
        Application.Run(new frmSplash());
    }
    public static DataTable LOGIN()
    {
        frmLogin2 log = new frmLogin2();
        log.ShowDialog();
        return dt;
    }
    private void frmLogin2_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)27)this.Close();
    }
}
}

下面是app.config

中的连接字符串
<add key="ConnStr" value="Data Source=.'SQLEXPRESS;AttachDbFilename=|DataDirectory|'POS.mdf;Integrated Security=True;User Instance=True"/>

我用的是Visual Studio 2008和SQL Server 2005 Express

c# Winform应用程序中的System.Data.SqlClient.Sql错误

确实,问题是在连接字符串内,而不是Data Source=部分。它是User Instance=True

除非你绝对肯定它的需要,否则我建议删除它- User Instance的默认值是False

我认为问题归结为权限/磁盘配额和其他系统管理相关的问题。在这里你可以找到更多关于User Instance是什么以及如何使用它。

您的数据源是问题所在。您目前有:

Data Source=.'SQLEXPRESS

但你需要的是(本地)像这样:

Data Source=(local)