1

i got the following error when i try to run my C# Winform Application on Client Machine

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

and here is the Application.Run code

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

and here is the form 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();
    }
}
}

and here is connection string in app.config

<add key="ConnStr" value="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\POS.mdf;Integrated Security=True;User Instance=True"/>

And I'm using Visual Studio 2008 and SQL Server 2005 Express

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ahmed Kamal
  • 89
  • 3
  • 10
  • 2
    Can you narrow it down to where this error occurs? (attach a debugger) – Matthew Mar 04 '13 at 13:35
  • @Matthew when i put the connection in try i got that error. failed to load a user instance of sql server due to a failure in starting the process of user instance.the connection will be closed – Ahmed Kamal Mar 04 '13 at 21:43
  • Have you seen [this](https://stackoverflow.com/questions/281500/error-failed-to-generate-a-user-instance-of-sql-server) ? You should also include the "full error message" in your Question itself. – Subbu Aug 18 '17 at 13:36
  • 2
    @mohsen Why put a bounty on a 4 year old question? It's not very answerable as is. – C. Helling Aug 18 '17 at 18:30
  • @C.Helling I Had this problem when i wanted to run my application on some client system . i had this problem on win7 and now i solved that but i can't remove bounty – mohsen Aug 19 '17 at 05:37
  • 3
    @mohsen Well if you solved the same problem you can answer it so that the next person that will have this problem might find your solution.... That's what this website is for - helping people.... – Zohar Peled Aug 21 '17 at 12:07

2 Answers2

2

Indeed, the problem is within the connection string, but not the Data Source= section. It is the User Instance=True

Unless you're absolutely positive about its need I suggest to remove it - the default value for User Instance is False.

I'm assuming the issue boils down to permissions/disk quotas and other sys admin related issues. Here you can find more on what the User Instance is and how to use it.

Bozhidar Stoyneff
  • 3,576
  • 1
  • 18
  • 28
0

Your data source is the problem. You currently have:

Data Source=.\SQLEXPRESS

But what you need is (local) like this:

Data Source=(local)
Devin L.
  • 437
  • 2
  • 12