Click here to Skip to main content
15,908,254 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have created a program and first stage of that program is to login to that application using username and password.

so now i want to open exe file from another pc which connected to network and it doesn't have sql as well.

when i click exe button it will ask user name and password.... and when we enter user name and password and hit enter it has to connect to sql installed pc.

C#
private void Btn1_Click(object sender, EventArgs e)
        {
            string connetionString = null;

            //string sql = null;
            string name = "";
            string pass = "";

            connetionString = "Data Source=172.21.1.91;Initial Catalog=EnqInfo;Network Library=DBMSSOCN;User Id=username; Password=password;Integrated Security=SSPI";


            using (SqlConnection con = new SqlConnection(connetionString))
            {
                //
                // Open the SqlConnection.
                //
                con.Open();
                //
                // The following code uses an SqlCommand based on the SqlConnection.
                //
                using (SqlCommand command = new SqlCommand("SELECT * FROM Login WHERE U_Name=@Usr", con))
                    {

                        command.Parameters.AddWithValue("@Usr", UName.Text);
                        SqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            name = reader.GetString(1);  // Name string
                            pass = reader.GetString(2); // Password string
                        }

                        if (name == UName.Text && pass == PWord.Text)
                        {

                            ClassEnq.Uname = UName.Text;
                            MessageBox.Show("Password Accepted");
                            this.Close();
                            setEnableToolStripMenuItem(true);
                            setEnableToolStripMenuItem1(true);
                            setDisableToolStripMenuItem(false);

                        }

                        else
                        {
                            MessageBox.Show("Password Incorrect, Please Re-Enter Your Password");
                            setEnableToolStripMenuItem(false);
                            setEnableToolStripMenuItem1(false);
                        }
                    }
                }



this is my code........

this is my error....

Unhandled exception has occurred in your application. if you click continue, the application will ignore this error and attempt to continue. if you click quit, the application will close immediately.

A network-related or instance-specific error occurred while establishing a connection to SQL server. the server was not found or was not accessible. Verify that the intance name is correct and that sql server is configured to allow remote connection. (provider: TCP Provider, error: 0-A connection attempt filed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond).


please provide me any good solution. i did everything but still has issues.

i noted this problem previously as well.
Posted
Updated 20-Jan-15 19:00pm
v2
Comments
Wendelius 21-Jan-15 1:00am    
Removed username and password from the connection string

As per your question it means that you need to use sql server from another network pc from your application. For you should change ConnectionString and make some configuration on SQL server Surface Area for remote connection. Already I implement this and get access from remote pc.

Please follow the links:

http://searchsqlserver.techtarget.com/tip/Using-Surface-Area-Configuration-to-lock-down-SQL-Server[^]

http://www.scrumdesk.com/Articles/HowToEnableSQLServerRemoteConnections.html[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900