Click here to Skip to main content
16,016,678 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi my code
i have one error on this line----
C#
Console.WriteLine("Result using a SQL statement: {0}", namedDB.ExecuteScalar(sqlCmd).ToString());

-----error is
----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 instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - No such host is known.)

C#
protected void btnClick_Click(object sender, EventArgs e)
   {
       //// Resolve the default Database object from the container.
       //// The actual concrete type is determined by the configuration settings.
       //Database defaultDB = EnterpriseLibraryContainer.Current.GetInstance<Database>();

       // Resolve a Database object from the container using the connection string name.
       Database namedDB = EnterpriseLibraryContainer.Current.GetInstance<Database>("grammart");

       // Resolve a SqlDatabase object from the container using the default database.
       SqlDatabase sqlServerDB = EnterpriseLibraryContainer.Current.GetInstance<Database>("grammart") as SqlDatabase;


       // Assume the method GetConnectionString exists in your application and
       // returns a valid connection string.
       string myConnectionString =GetConnectionString();

       SqlDatabase sqlDatabase = new SqlDatabase(myConnectionString);

       string sUser = txtUserId.Text;
       string pass = txtPassword.Text;
       using (DbCommand sqlCmd = namedDB.GetSqlStringCommand("select count(UserID) as UserID from M_User where UserID= '" + sUser + "'and password = '" + pass + "'"))
       {
           // Call the ExecuteScalar method of the command.
           Console.WriteLine("Result using a SQL statement: {0}", namedDB.ExecuteScalar(sqlCmd).ToString());


       }


   }

   private string GetConnectionString()
   {

       Database namedDB = DatabaseFactory.CreateDatabase("grammart");
       return namedDB.ConnectionString;

       //throw new NotImplementedException();

   }
Posted
Updated 8-Aug-12 20:59pm
v3
Comments
Abdul Quader Mamun 9-Aug-12 2:59am    
Edited for code block.

1 solution

 
Share this answer
 
Comments
niki_nilu 9-Aug-12 5:49am    
pls tell me how to use
executescalr(cmd)
when i used query.

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