1

当我尝试在客户端计算机上运行我的 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

这是 Application.Run 代码

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

这是表单登录代码

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

4

2 回答 2

2

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

除非您对它的需要非常肯定,否则我建议将其删除 - 默认User Instance值为False.

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

于 2017-08-24T15:10:38.037 回答
0

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

Data Source=.\SQLEXPRESS

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

Data Source=(local)
于 2017-08-24T00:18:43.603 回答