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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to connect directly to the table in the database.

how to connect directly to the table in the database.

Scheduled Pinned Locked Moved ASP.NET
databasesecuritytutorialquestion
4 Posts 2 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.
  • P Offline
    P Offline
    pandapatin
    wrote on last edited by
    #1

    im building a login procedure.im going to compare a text user inserted with a data in a table.at this time im using the command Dim Myconn As New SqlClient.SqlConnection("Data Source=HAPPYFAM-B614E1\SQLEXPRESS;Initial Catalog=psm;Integrated Security=True") its it right or wrong?how could i do such thing.

    C 1 Reply Last reply
    0
    • P pandapatin

      im building a login procedure.im going to compare a text user inserted with a data in a table.at this time im using the command Dim Myconn As New SqlClient.SqlConnection("Data Source=HAPPYFAM-B614E1\SQLEXPRESS;Initial Catalog=psm;Integrated Security=True") its it right or wrong?how could i do such thing.

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      That will create a connection to the database, but nothing more. If you need to search for data you'll need a SELECT statement to be passed to the SQL Server.

      Dim cmd As SqlCommand = New SqlCommand()
      cmd.Connection = Myconn;
      cmd.CommandText = "SELECT COUNT(*) FROM MyTable WHERE SomeColumn = @someValue"
      cmd.Parameters.Add("@someValue", userEnteredText)
      Dim count As Integer = cmd.ExecuteScalar()
      ' count will contain the number of rows where SomeColumn = the user entered value

      Does this help? ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

      P 1 Reply Last reply
      0
      • C Colin Angus Mackay

        That will create a connection to the database, but nothing more. If you need to search for data you'll need a SELECT statement to be passed to the SQL Server.

        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = Myconn;
        cmd.CommandText = "SELECT COUNT(*) FROM MyTable WHERE SomeColumn = @someValue"
        cmd.Parameters.Add("@someValue", userEnteredText)
        Dim count As Integer = cmd.ExecuteScalar()
        ' count will contain the number of rows where SomeColumn = the user entered value

        Does this help? ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

        P Offline
        P Offline
        pandapatin
        wrote on last edited by
        #3

        this is the code Dim conMyData As SqlConnection = New SqlClient.SqlConnection("data source=HAPPYFAM-B614E1\SQLEXPRESS\sqlexpress.psm.dbo") conMyData = New SqlConnection() cmdSelect = New SqlCommand("DBAuthenticate", conMyData) cmdSelect.CommandType = CommandType.StoredProcedure paramReturnValue = cmdSelect.Parameters.Add("RETURN_VALUE", SqlDbType.Int) paramReturnValue.Direction = ParameterDirection.ReturnValue cmdSelect.Parameters.AddWithValue("@NoPekerja", strUsername) cmdSelect.Parameters.AddWithValue("@pWord", strPassword) conMyData.Open() the problem is connMyData.Open() error msg : An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

        C 1 Reply Last reply
        0
        • P pandapatin

          this is the code Dim conMyData As SqlConnection = New SqlClient.SqlConnection("data source=HAPPYFAM-B614E1\SQLEXPRESS\sqlexpress.psm.dbo") conMyData = New SqlConnection() cmdSelect = New SqlCommand("DBAuthenticate", conMyData) cmdSelect.CommandType = CommandType.StoredProcedure paramReturnValue = cmdSelect.Parameters.Add("RETURN_VALUE", SqlDbType.Int) paramReturnValue.Direction = ParameterDirection.ReturnValue cmdSelect.Parameters.AddWithValue("@NoPekerja", strUsername) cmdSelect.Parameters.AddWithValue("@pWord", strPassword) conMyData.Open() the problem is connMyData.Open() error msg : An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          pandapatin wrote:

          An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.

          And have you changed the default settings. SQL Server 2005 is locked down by default. It can only be accessed by processes running on the same machine. You have to allow it to access the network if you want it to be accessible to other machines. SQL Server will have installed a tool to allow you to change its configuration and security settings (I don't have SQL Server 2005 on the machine I'm using so I can't tell you exactly what it is called or how to change the settings) ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

          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