Click here to Skip to main content
15,920,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My global function code as follows;
C#
 using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;


namespace Faculty_Schedule_Time_Table
{
    //class Gloabal_Function
        public class Global_Function
    {

            public SqlConnection con = new SqlConnection();
            private string connectionstring ="Data Source=NARASIMAN;connect timeout=120;initial catalog=HIMT;username=sa;";
            private SqlCommand cmd;
            private SqlDataReader dr;

            public string error;

            public Global_Function()
            {

            }

            public void BindCon()
            {
                con = new SqlConnection();
                con.ConnectionString = connectionstring;
                con.Open();

            }

            public void insertdata(String SQL)
            {
                try
                {
                    BindCon();
                    cmd = new SqlCommand(SQL, con);
                    cmd.ExecuteReader();
                }
                 catch(Exception e1)
                  {
                   error = e1.Message.ToString();
                  }
            }
            public SqlDataReader ReadSql(string SQL)
            {

            con = new SqlConnection(connectionstring);
            con.Open();
            cmd  = new SqlCommand(SQL,con);
            dr = cmd.ExecuteReader();
            return (dr);
            
        }
           
            public string CntString()
        {
            return connectionstring;
        }
    }
}

When I run error shows keyword not supported username

The above error shows in the following line as follows;
C#
public SqlDataReader ReadSql(string SQL)
       {
  con = new SqlConnection(connectionstring); // in this line above error shows
       con.Open();
       cmd  = new SqlCommand(SQL,con);
       dr = cmd.ExecuteReader();
       return (dr);

   }


Please help me.

[Edit]Code block added[/Edit]
Posted
Updated 10-Feb-13 4:52am
v2

For correct connection strings read this : http://www.connectionstrings.com/sql-server-2012[^]
 
Share this answer
 
use "user id" instead of "user name" in connection string
 
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