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. General Programming
  3. C#
  4. problems connecting to local database

problems connecting to local database

Scheduled Pinned Locked Moved C#
databasecsharpvisual-studiographicssecurity
5 Posts 3 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.
  • V Offline
    V Offline
    valiovalio
    wrote on last edited by
    #1

    Hi, I`m using visual studio 2005. I`ve created a local database "db.mdf", and I`m just trying to connect with, but when I run code it throws an exception: ServerVersion = 'sqlconn.ServerVersion' threw an exception of type 'System.InvalidOperationException' and after that the program stops to respond...What should I do to connect? here is my code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace DB { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string c = "Data Source=(local);database=db.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; SqlConnection sqlconn = new SqlConnection(c); sqlconn.Open(); string query = "SELECT ASM_VARDAS, ASM_PAVARDE, ASM_GIM_DATA FROM v_ASMENYS WHERE ASM_AK = "; SqlCommand sqlcomm = new SqlCommand(query, sqlconn); SqlDataReader reader = sqlcomm.ExecuteReader(); reader.Read(); } } }

    L 1 Reply Last reply
    0
    • V valiovalio

      Hi, I`m using visual studio 2005. I`ve created a local database "db.mdf", and I`m just trying to connect with, but when I run code it throws an exception: ServerVersion = 'sqlconn.ServerVersion' threw an exception of type 'System.InvalidOperationException' and after that the program stops to respond...What should I do to connect? here is my code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace DB { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string c = "Data Source=(local);database=db.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; SqlConnection sqlconn = new SqlConnection(c); sqlconn.Open(); string query = "SELECT ASM_VARDAS, ASM_PAVARDE, ASM_GIM_DATA FROM v_ASMENYS WHERE ASM_AK = "; SqlCommand sqlcomm = new SqlCommand(query, sqlconn); SqlDataReader reader = sqlcomm.ExecuteReader(); reader.Read(); } } }

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      valiovalio wrote:

      database=db.mdf;

      I think that is 'Attach Database=db.mdf;'

      xacc.ide-0.1.3.2

      V 1 Reply Last reply
      0
      • L leppie

        valiovalio wrote:

        database=db.mdf;

        I think that is 'Attach Database=db.mdf;'

        xacc.ide-0.1.3.2

        V Offline
        V Offline
        valiovalio
        wrote on last edited by
        #3

        You meant 'AttachDbFilename=db.mdf;'?

        E 1 Reply Last reply
        0
        • V valiovalio

          You meant 'AttachDbFilename=db.mdf;'?

          E Offline
          E Offline
          esjq
          wrote on last edited by
          #4

          Shouldn't it be like this: string c = "Data Source=(local);Initial Catalog=db.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; HTH

          V 1 Reply Last reply
          0
          • E esjq

            Shouldn't it be like this: string c = "Data Source=(local);Initial Catalog=db.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; HTH

            V Offline
            V Offline
            valiovalio
            wrote on last edited by
            #5

            I don`t think it`s a problem with connection string... I`m not able to connect no mathet what I write in that connection string...

            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