Solved

C Sharp

Posted on 2014-03-28
4
262 Views
Last Modified: 2014-04-06
Hi Guys ,

I have finished building my first windows form application with C# and now I don't know how to continue and make it works for users.

I used visual studio when I built this app and when I copy the solution to the user computer and launch the EXE file all works fine but I'm sure this is not the way to do it.

Another things I have to mention that the application database located in the SQL server and I have pointed the application to my SQL server by String code

Please can you direct me how to compile my application as a production app ....I hope you understand my question as I really new with programming.


Thanks ,
0
Comment
Question by:Moti Mashiah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 13

Assisted Solution

by:Naman Goel
Naman Goel earned 500 total points
ID: 39963418
You need to compile your project in Release and package it with some installer,

http://www.dreamincode.net/forums/topic/58021-deploying-a-c%23-application-visual-studio-setup-project/

for connection string you can use some sort of Application config file


Start with: http://msdn.microsoft.com/en-us/library/1xtk877y.aspx. For connection string-specific information, please see: http://msdn.microsoft.com/en-us/library/ms254494(v=vs.110).aspx

At its simplest, the app.config is an XML file with built-in configuration sections and the ability to add your own custom settings. Custom settings can be added by using the built-in configuration sections (such as connectionStrings) or adding your own custom configuration sections (an advanced topic, but very powerful for building strongly-typed configuration files).

Web applications typically have a web.config, while Windows GUI/service applications have an app.config file.

Application config files inherit settings from global configuration files, e.g. the machine.config.
Reading from the App.Config

Connection strings have a pre-defined schema that you can use. Note that this small snippet is actually a valid app.config (or web.config) file:

<?xml version="1.0"?>
<configuration>
    <connectionStrings>  
        <add name="MyKey"
             connectionString="Data Source=localhost;Initial Catalog=ABC;"
             providerName="System.Data.SqlClient"/>
    </connectionStrings>
</configuration>

Once you have defined your app.config, you can read it in code using the ConfigurationManager class. Don't be intimidated by the verbose MSDN examples; it's actually quite simple.

string connectionString = ConfigurationManager.ConnectionStrings["MyKey"].ConnectionString;

Writing to the App.Config

Frequently changing the *.config files is usually not a good idea, but it sounds like you only want to perform one-time setup.

See: Change connection string & reload app.config at run time which describes how to update the connectionStrings section of the *.config file at runtime.

Note that ideally you would perform such configuration changes from a simple installer.
0
 
LVL 1

Accepted Solution

by:
Moti Mashiah earned 0 total points
ID: 39963810
Regarding the Connection I did not configure any connection in app.config file al I did during the implementation is in any class or form I wrote string to my database server:

See example:

namespace Alt8
{

    public partial class frmLogin : Form
    {

        public frmLogin()
        {
            InitializeComponent();
            txtpass_Login.PasswordChar = '*';
            txtpass_Login.MaxLength = 12;  
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string Conn = "Data Source=srv-db-02;Initial Catalog=rmsmasterdbtest;Persist Security Info=True;User ID=test;Password=masterB4";
                SqlConnection Myconn = new SqlConnection(Conn);
                SqlCommand SelectCommand = new SqlCommand("select * from rmsmasterdbtest.dbo.UserLogin where Fname='" + this.txtUsernamelogin.Text + "' and passw='" + this.txtpass_Login.Text + "' ;", Myconn);

                SqlDataReader reader;
                Myconn.Open();
                reader = SelectCommand.ExecuteReader();
                int count = 0;
                while (reader.Read())
                {
                    count = count + 1;
                }
                if (count == 1)
                {
                    this.Hide();
                    frmMainmanu f2 = new frmMainmanu("Welcome," +txtUsernamelogin.Text);
                    f2.ShowDialog();
                }
                else if (count > 1)
                {
                    MessageBox.Show("Duplicate username and password.....access denied");
                }
                else
                    MessageBox.Show("Username and Password is Not Correct");
                Myconn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
0
 
LVL 13

Assisted Solution

by:Naman Goel
Naman Goel earned 500 total points
ID: 39964114
In any ways the database should be there in customer environment, so either you can create a database using your installer program, so in that case you need to ask user for username and password for accessing that database

following article explains about creating database programmatically

http://support.microsoft.com/kb/305079

can need to pass that details in connection string in your class.
0
 
LVL 1

Author Closing Comment

by:Moti Mashiah
ID: 39981033
Thank for really great help
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question