Dec 1, 2013

C# Sql Server 2008 Database Connection

using System.Data;  // Include This In Your Code
using System.Data.SqlClient; // Include This In Your Code

public class DBConnections
    {
        public SqlConnection ConnectDB() // i create a connection in this function and return the connection
        {
   string ConnectionString = @"Server=localhost;Database=dbname;Trusted_Connection=True";
   //u can use localhost as the server name or user ur sql server instance name

   // below commented code is to connect to a remote database. u have to configure database to do this        //string ConnectionString = "Data Source=192.168.0.1,1433;Network Library=DBMSSOCN;Initial           //Catalog=dbname;User ID=useridhere;Password=passwordhere";

            SqlConnection con = new SqlConnection(ConnectionString);
         
            try
            {
                con.Open();              
            }
            catch (SqlException)
            {
         
            }
            catch (Exception ex )
            {
                MessageBox.Show(ex.Message);
            }

            return con;
        }
    }

No comments:

JWT Token Decode Using Jquery

When it come to authentication we use many mechanism. Ones the user authenticated we must keep these details somewhere safe. So we can share...