วันจันทร์ที่ 13 กรกฎาคม พ.ศ. 2558

connection Sql server

If your system has the Windows Firewall 
configured, it must be configured to allow the remote connection to 
communicate with the SQL Server executable. Follow the steps given below
 to ensure connectivity through the firewall.
1. Start the Control Panel on the computer running SQL Server 2005.
2. Double Click on Windows Firewall.
3. Click on the Exceptions tab.
4. Click on the Add Program button.
5.
 Add the path of sqlsrvr.exe. By default the sqlsrvr.exe is installed at
 <Drive>\Program Files\Microsoft SQL 
Server\MSSQL.1\MSSQL\Binn\sqlservr.exe 
 
private void SelectEmployee()
        {
            try
            {
                DataTable data = null;
                using (SqlConnection connection = new SqlConnection(connectionstring))
                {
                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }

                    using (SqlCommand cmdSelect = connection.CreateCommand())
                    {
                        cmdSelect.CommandText = "SELECT * FROM Employee;";
                        cmdSelect.CommandType = CommandType.Text;
                        data = new DataTable();
                        using (SqlDataReader reader = cmdSelect.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                data.Load(reader);
                            }
                        }
                    }
                }
                if (data!=null)
                {
                    this.datagrdviewEmp.DataSource = data;
                }
               
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

string connectionstring = @"Server=Server IP/Name;Database=Your DB; Uid=user id; pwd=your sql passwrod;";
 
http://highoncoding.com/Articles/551_How_to_Access_SQL_Server_2005_from_the_Windows_Mobile_Devices.aspx 

ไม่มีความคิดเห็น:

แสดงความคิดเห็น