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. ASP.net/SQL newbie Question

ASP.net/SQL newbie Question

Scheduled Pinned Locked Moved ASP.NET
databasehelpcsharpasp-netcom
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
    Planker
    wrote on last edited by
    #1

    I followed the article here http://www.kirupa.com/net/sql\_asp\_introduction.htm everything compiles ok but when it get to opening the database I get error message An attempt to attach an auto-named database for file C:\Path\Games.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share I do not have any other databases with the same name and it is on the C drive so leads me to believe for some reason it can not open the database. could someone please help me with this. Thanks

    M 1 Reply Last reply
    0
    • P Planker

      I followed the article here http://www.kirupa.com/net/sql\_asp\_introduction.htm everything compiles ok but when it get to opening the database I get error message An attempt to attach an auto-named database for file C:\Path\Games.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share I do not have any other databases with the same name and it is on the C drive so leads me to believe for some reason it can not open the database. could someone please help me with this. Thanks

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      You can check out here[^]

      P 1 Reply Last reply
      0
      • M minhpc_bk

        You can check out here[^]

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

        ok i figured out what was wrong, .net 2.0 needed to be reinstalled, my app now runs but does not write to the database, is there something wrong with my code to write to the database? SqlConnection connection; protected void Page_Load(object sender, EventArgs e) { connection = new SqlConnection(ConfigurationManager.ConnectionStrings["GameConnection"].ConnectionString); } protected void btnSubmit_Click(object sender, EventArgs e) { SqlCommand command = new SqlCommand("INSERT INTO gameTable(gameName, gamePlatform) VALUES (@id_gameName,@id_gmaePlatform)", connection); SqlParameter nameContent = new SqlParameter("@id_gameName", SqlDbType.VarChar); nameContent.Value = txtName.Text; command.Parameters.Add(nameContent); SqlParameter platformContent = new SqlParameter("@id_gamePlatform", SqlDbType.VarChar); platformContent.Value = txtPlatform.Text; command.Parameters.Add(platformContent); connection.Open(); command.BeginExecuteNonQuery(); connection.Close(); Response.Redirect("Results.aspx"); }

        M 1 Reply Last reply
        0
        • P Planker

          ok i figured out what was wrong, .net 2.0 needed to be reinstalled, my app now runs but does not write to the database, is there something wrong with my code to write to the database? SqlConnection connection; protected void Page_Load(object sender, EventArgs e) { connection = new SqlConnection(ConfigurationManager.ConnectionStrings["GameConnection"].ConnectionString); } protected void btnSubmit_Click(object sender, EventArgs e) { SqlCommand command = new SqlCommand("INSERT INTO gameTable(gameName, gamePlatform) VALUES (@id_gameName,@id_gmaePlatform)", connection); SqlParameter nameContent = new SqlParameter("@id_gameName", SqlDbType.VarChar); nameContent.Value = txtName.Text; command.Parameters.Add(nameContent); SqlParameter platformContent = new SqlParameter("@id_gamePlatform", SqlDbType.VarChar); platformContent.Value = txtPlatform.Text; command.Parameters.Add(platformContent); connection.Open(); command.BeginExecuteNonQuery(); connection.Close(); Response.Redirect("Results.aspx"); }

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Planker wrote:

          command.BeginExecuteNonQuery(); connection.Close();

          You make an asynchronous call to insert data, but you close the connection right after that then how data can be inserted into DB. You might also double check the parameter name gmaePlatform as well.

          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