Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. New to ASP.NET need help

New to ASP.NET need help

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasehelp
15 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Hari CodeBlogger

    i get an error when i click submit button {"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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"}

    T Offline
    T Offline
    thatraja
    wrote on last edited by
    #6

    From link[^]:

    Basically, when you failed to connect to your SQL Server, the issue could be: 1) Network issue, 2) SQL Server configuration issue. 3) Firewall issue, 4) Client driver issue, 5) Application configuration issue. 6) Authentication and logon issue.

    Check these Steps to troubleshoot SQL connectivity issues[^] SQL Server 2005 Connectivity Issue Troubleshoot - Part I[^] Troubleshoot Connectivity Issue in SQL Server 2005 - Part II[^] Troubleshoot Connectivity Issue in SQL Server 2005 - Part III[^]

    thatraja

    Code converters | Education Needed | Improve EverythingNew

    1 Reply Last reply
    0
    • L Lost User

      Check in your web.config if you have specified properly the connection strings. And one thing are you using MVC?

      H Offline
      H Offline
      Hari CodeBlogger
      wrote on last edited by
      #7

      nope. i just resolved that but got an syntax error in particular line "int temp = Convert.ToInt32(com.ExecuteScalar().ToString());" code SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["userConnectionString"].ConnectionString); cn.Open(); string sel = "select count(*) from Table where username = '" + username.Text + "'"; SqlCommand com = new SqlCommand(sel, cn); int temp = Convert.ToInt32(com.ExecuteScalar().ToString()); if(temp==1) { Response.Write("User already exists..!!"); } cn.Close();

      L Richard DeemingR 2 Replies Last reply
      0
      • H Hari CodeBlogger

        nope. i just resolved that but got an syntax error in particular line "int temp = Convert.ToInt32(com.ExecuteScalar().ToString());" code SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["userConnectionString"].ConnectionString); cn.Open(); string sel = "select count(*) from Table where username = '" + username.Text + "'"; SqlCommand com = new SqlCommand(sel, cn); int temp = Convert.ToInt32(com.ExecuteScalar().ToString()); if(temp==1) { Response.Write("User already exists..!!"); } cn.Close();

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #8

        oh! great..(y) :)

        H 1 Reply Last reply
        0
        • L Lost User

          oh! great..(y) :)

          H Offline
          H Offline
          Hari CodeBlogger
          wrote on last edited by
          #9

          I got an error An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code view details ---> {"Incorrect syntax near the keyword 'Table'."} code: SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["userConnectionString"].Con‌​nectionString); cn.Open(); string sel = "select count(*) from Table where username = '" + username.Text + "'"; SqlCommand com = new SqlCommand(sel, cn); int temp = Convert.ToInt32(com.ExecuteScalar().ToString()); if(temp==1) { Response.Write("User already exists..!!"); }cn.Close();

          L C 2 Replies Last reply
          0
          • H Hari CodeBlogger

            I got an error An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code view details ---> {"Incorrect syntax near the keyword 'Table'."} code: SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["userConnectionString"].Con‌​nectionString); cn.Open(); string sel = "select count(*) from Table where username = '" + username.Text + "'"; SqlCommand com = new SqlCommand(sel, cn); int temp = Convert.ToInt32(com.ExecuteScalar().ToString()); if(temp==1) { Response.Write("User already exists..!!"); }cn.Close();

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #10

            One thing I would like to mention Hari is seldom use select * from .... always have a habit to write all the column names. Its a very good practice.:) I guess use the name propertyfor the textbox from where you need the name and then write the name in the "--" that might work out. and from the error it seems you miss some Dll's assemblies.. please check using a debugger where exactly you are getting that exception. thanks

            H 1 Reply Last reply
            0
            • L Lost User

              One thing I would like to mention Hari is seldom use select * from .... always have a habit to write all the column names. Its a very good practice.:) I guess use the name propertyfor the textbox from where you need the name and then write the name in the "--" that might work out. and from the error it seems you miss some Dll's assemblies.. please check using a debugger where exactly you are getting that exception. thanks

              H Offline
              H Offline
              Hari CodeBlogger
              wrote on last edited by
              #11

              thanx (y)

              1 Reply Last reply
              0
              • H Hari CodeBlogger

                I got an error An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code view details ---> {"Incorrect syntax near the keyword 'Table'."} code: SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["userConnectionString"].Con‌​nectionString); cn.Open(); string sel = "select count(*) from Table where username = '" + username.Text + "'"; SqlCommand com = new SqlCommand(sel, cn); int temp = Convert.ToInt32(com.ExecuteScalar().ToString()); if(temp==1) { Response.Write("User already exists..!!"); }cn.Close();

                C Offline
                C Offline
                Chris Quinn
                wrote on last edited by
                #12

                Table is a reserved word in SQL, so it is a bad idea to call a table "Table" - call it something significant, like Registration or UserReg In MSSQl, if you are using a reserved word for something else, such as a table or column name, you must surround it with square brackets e.g. SELECT * from [TABLE] ......

                ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

                H 1 Reply Last reply
                0
                • C Chris Quinn

                  Table is a reserved word in SQL, so it is a bad idea to call a table "Table" - call it something significant, like Registration or UserReg In MSSQl, if you are using a reserved word for something else, such as a table or column name, you must surround it with square brackets e.g. SELECT * from [TABLE] ......

                  ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

                  H Offline
                  H Offline
                  Hari CodeBlogger
                  wrote on last edited by
                  #13

                  worked.. thanx. (y)

                  1 Reply Last reply
                  0
                  • H Hari CodeBlogger

                    nope. i just resolved that but got an syntax error in particular line "int temp = Convert.ToInt32(com.ExecuteScalar().ToString());" code SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["userConnectionString"].ConnectionString); cn.Open(); string sel = "select count(*) from Table where username = '" + username.Text + "'"; SqlCommand com = new SqlCommand(sel, cn); int temp = Convert.ToInt32(com.ExecuteScalar().ToString()); if(temp==1) { Response.Write("User already exists..!!"); } cn.Close();

                    Richard DeemingR Offline
                    Richard DeemingR Offline
                    Richard Deeming
                    wrote on last edited by
                    #14

                    Your code is susceptible to SQL Injection[^]. For example, if the user types Robert';DROP TABLE [Table];-- in the username textbox, your query becomes:

                    select count(*) from Table where username = 'Robert';DROP TABLE [Table];--'

                    That's actually two queries; one to select the number of records with the username "Robert", and one to delete the entire table. The "--" at the end comments out the rest of the query. It's quite easy to fix:

                    // SqlConnection implements IDisposable, so wrap it in a "using" block:
                    using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["userConnectionString"].ConnectionString))
                    {
                    cn.Open();

                    // Use a parameterized query to avoid SQL injection:
                    string sel = "select count(\*) from \[Table\] where username = @username";
                    
                    // SqlCommand also implements IDisposable:
                    using (SqlCommand com = new SqlCommand(sel, cn))
                    {
                        // Add the parameter to the command:
                        com.Parameters.AddWithValue("@username", username.Text);
                        
                        int temp = Convert.ToInt32(com.ExecuteScalar());
                        if (temp == 1)
                        {
                            Response.Write("User already exists..!!");
                        }
                    }
                    

                    }


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                    H 1 Reply Last reply
                    0
                    • Richard DeemingR Richard Deeming

                      Your code is susceptible to SQL Injection[^]. For example, if the user types Robert';DROP TABLE [Table];-- in the username textbox, your query becomes:

                      select count(*) from Table where username = 'Robert';DROP TABLE [Table];--'

                      That's actually two queries; one to select the number of records with the username "Robert", and one to delete the entire table. The "--" at the end comments out the rest of the query. It's quite easy to fix:

                      // SqlConnection implements IDisposable, so wrap it in a "using" block:
                      using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["userConnectionString"].ConnectionString))
                      {
                      cn.Open();

                      // Use a parameterized query to avoid SQL injection:
                      string sel = "select count(\*) from \[Table\] where username = @username";
                      
                      // SqlCommand also implements IDisposable:
                      using (SqlCommand com = new SqlCommand(sel, cn))
                      {
                          // Add the parameter to the command:
                          com.Parameters.AddWithValue("@username", username.Text);
                          
                          int temp = Convert.ToInt32(com.ExecuteScalar());
                          if (temp == 1)
                          {
                              Response.Write("User already exists..!!");
                          }
                      }
                      

                      }


                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      H Offline
                      H Offline
                      Hari CodeBlogger
                      wrote on last edited by
                      #15

                      thanx. :)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups