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. Cannot connect into SQL Server using C#

Cannot connect into SQL Server using C#

Scheduled Pinned Locked Moved C#
helpcsharpvisual-studiodatabasesql-server
8 Posts 3 Posters 1 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.
  • G Offline
    G Offline
    Gindi Bar Yahav
    wrote on last edited by
    #1

    Bey guys, i have a little problem, so if you can help me ill thank you... i built a Sql server using Visual Stuido 2008 ( it created me a file name my_database.sdf ). now i am tring to connect to the sql server i have created, i using the code below:

    public void Connect()
    {
    this.han = new SqlConnection(@"Data Source=C:\Users\יהב\Documents\Visual Studio 2008\Projects\ADOtutorial\ADOtutorial\my_database.sdf;Persist Security Info=True;Application Name=ConnectDB");
    Console.WriteLine(this.han.ConnectionString);
    try
    {
    this.han.Open();
    }
    catch (NullReferenceException e)
    {
    Console.WriteLine(e);
    }
    catch (SqlException e)
    {
    Console.WriteLine(e);
    }
    }

    this is a code in class, the class using this.han to make theconnection, the connection string i have copied from the connection strind i got from VS when i did motify connection -> advance. but for some resons i cant connect the error i got:

    Data Source=C:\Users\יהב\Documents\Visual Studio 2008\Projects\ADOtutorial\ADOtu
    torial\my_database.sdf;Persist Security Info=True;Application Name=ConnectDB
    System.Data.SqlClient.SqlException: אירעה שגיאה הקשורה לרשת או שגיאה ספציפית למו
    פע במהלך יצירת חיבור ל- SQL Server. השרת לא נמצא או שאינו נגיש. ודא כי שם המופע
    נכון וכי SQL Server מוגדר לאפשר חיבורים מרוחקים. (provider: ממשקי רשת של SQL, e
    rror: 26 - שגיאה באיתור שרת/מופע שצוין)
    ב- System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exceptio
    n, Boolean breakConnection)
    ב- System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateOb
    ject stateObj)
    ב- System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInterna
    lConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boo
    lean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection
    owningObject)
    ב- System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo
    serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire
    , SqlConnection owningObject)
    ב- System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String hos
    t, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObjec
    t, SqlConnectionString connectionOptions, Int64 timerStart)
    ב- System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConn

    L S 2 Replies Last reply
    0
    • G Gindi Bar Yahav

      Bey guys, i have a little problem, so if you can help me ill thank you... i built a Sql server using Visual Stuido 2008 ( it created me a file name my_database.sdf ). now i am tring to connect to the sql server i have created, i using the code below:

      public void Connect()
      {
      this.han = new SqlConnection(@"Data Source=C:\Users\יהב\Documents\Visual Studio 2008\Projects\ADOtutorial\ADOtutorial\my_database.sdf;Persist Security Info=True;Application Name=ConnectDB");
      Console.WriteLine(this.han.ConnectionString);
      try
      {
      this.han.Open();
      }
      catch (NullReferenceException e)
      {
      Console.WriteLine(e);
      }
      catch (SqlException e)
      {
      Console.WriteLine(e);
      }
      }

      this is a code in class, the class using this.han to make theconnection, the connection string i have copied from the connection strind i got from VS when i did motify connection -> advance. but for some resons i cant connect the error i got:

      Data Source=C:\Users\יהב\Documents\Visual Studio 2008\Projects\ADOtutorial\ADOtu
      torial\my_database.sdf;Persist Security Info=True;Application Name=ConnectDB
      System.Data.SqlClient.SqlException: אירעה שגיאה הקשורה לרשת או שגיאה ספציפית למו
      פע במהלך יצירת חיבור ל- SQL Server. השרת לא נמצא או שאינו נגיש. ודא כי שם המופע
      נכון וכי SQL Server מוגדר לאפשר חיבורים מרוחקים. (provider: ממשקי רשת של SQL, e
      rror: 26 - שגיאה באיתור שרת/מופע שצוין)
      ב- System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exceptio
      n, Boolean breakConnection)
      ב- System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateOb
      ject stateObj)
      ב- System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInterna
      lConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boo
      lean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection
      owningObject)
      ב- System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo
      serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire
      , SqlConnection owningObject)
      ב- System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String hos
      t, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObjec
      t, SqlConnectionString connectionOptions, Int64 timerStart)
      ב- System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConn

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

      .sdf files are SQL CE databases, not SQL Server. You have created an "embedded" database. The database that you wanted (SQL Server) has the file-extension ".mdf". What did you use to create the database?

      I are troll :)

      G 1 Reply Last reply
      0
      • L Lost User

        .sdf files are SQL CE databases, not SQL Server. You have created an "embedded" database. The database that you wanted (SQL Server) has the file-extension ".mdf". What did you use to create the database?

        I are troll :)

        G Offline
        G Offline
        Gindi Bar Yahav
        wrote on last edited by
        #3

        thanks for the replay, umm i didnt know that this is not a SQL Server... i open new Console APP (to check this, acualy i am building a program to my website in WIN but now i need to learn it first.. i done it before with MYSQL but...) so~, i clicked on Add new item (in the sulution explorer) and them local database connection. umm... and them i saw the database in the database explorer and i could edit tables, add tables etc... if its not mysql, can you explin me where i can find the way to connect to that type of sql server?

        Gindi Bar Yahav - Web & Software defeloper.

        L 1 Reply Last reply
        0
        • G Gindi Bar Yahav

          thanks for the replay, umm i didnt know that this is not a SQL Server... i open new Console APP (to check this, acualy i am building a program to my website in WIN but now i need to learn it first.. i done it before with MYSQL but...) so~, i clicked on Add new item (in the sulution explorer) and them local database connection. umm... and them i saw the database in the database explorer and i could edit tables, add tables etc... if its not mysql, can you explin me where i can find the way to connect to that type of sql server?

          Gindi Bar Yahav - Web & Software defeloper.

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

          Do you want: * SQL Server (Serves lots of people at once) * SQL CE (Embedded database) * MySQL (...) ? The SQLConnection is used for SQL Server, not MySQL. SQL Server might be installed by the VS2008 setup, MySQL is a separate download. Downloads be here[^], tutorials on SQL Server are here[^].

          I are troll :)

          G 1 Reply Last reply
          0
          • L Lost User

            Do you want: * SQL Server (Serves lots of people at once) * SQL CE (Embedded database) * MySQL (...) ? The SQLConnection is used for SQL Server, not MySQL. SQL Server might be installed by the VS2008 setup, MySQL is a separate download. Downloads be here[^], tutorials on SQL Server are here[^].

            I are troll :)

            G Offline
            G Offline
            Gindi Bar Yahav
            wrote on last edited by
            #5

            thanks you very moch for your help, what i am looking for is a software database so i dont really i need very big database, but ill try to work with SQL server to learn it... the last qustion if you can help me is if you know where i can find database hosting

            Gindi Bar Yahav - Web & Software defeloper.

            L 1 Reply Last reply
            0
            • G Gindi Bar Yahav

              thanks you very moch for your help, what i am looking for is a software database so i dont really i need very big database, but ill try to work with SQL server to learn it... the last qustion if you can help me is if you know where i can find database hosting

              Gindi Bar Yahav - Web & Software defeloper.

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

              Gindi Bar Yahav wrote:

              where i can find database hosting

              I'd like to recommend ASP Spider[^]. It's the ideal place to try out new ASP.NET/SQL projects, since it is free.

              I are troll :)

              1 Reply Last reply
              0
              • G Gindi Bar Yahav

                Bey guys, i have a little problem, so if you can help me ill thank you... i built a Sql server using Visual Stuido 2008 ( it created me a file name my_database.sdf ). now i am tring to connect to the sql server i have created, i using the code below:

                public void Connect()
                {
                this.han = new SqlConnection(@"Data Source=C:\Users\יהב\Documents\Visual Studio 2008\Projects\ADOtutorial\ADOtutorial\my_database.sdf;Persist Security Info=True;Application Name=ConnectDB");
                Console.WriteLine(this.han.ConnectionString);
                try
                {
                this.han.Open();
                }
                catch (NullReferenceException e)
                {
                Console.WriteLine(e);
                }
                catch (SqlException e)
                {
                Console.WriteLine(e);
                }
                }

                this is a code in class, the class using this.han to make theconnection, the connection string i have copied from the connection strind i got from VS when i did motify connection -> advance. but for some resons i cant connect the error i got:

                Data Source=C:\Users\יהב\Documents\Visual Studio 2008\Projects\ADOtutorial\ADOtu
                torial\my_database.sdf;Persist Security Info=True;Application Name=ConnectDB
                System.Data.SqlClient.SqlException: אירעה שגיאה הקשורה לרשת או שגיאה ספציפית למו
                פע במהלך יצירת חיבור ל- SQL Server. השרת לא נמצא או שאינו נגיש. ודא כי שם המופע
                נכון וכי SQL Server מוגדר לאפשר חיבורים מרוחקים. (provider: ממשקי רשת של SQL, e
                rror: 26 - שגיאה באיתור שרת/מופע שצוין)
                ב- System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exceptio
                n, Boolean breakConnection)
                ב- System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateOb
                ject stateObj)
                ב- System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInterna
                lConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boo
                lean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection
                owningObject)
                ב- System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo
                serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire
                , SqlConnection owningObject)
                ב- System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String hos
                t, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObjec
                t, SqlConnectionString connectionOptions, Int64 timerStart)
                ב- System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConn

                S Offline
                S Offline
                SayreCC
                wrote on last edited by
                #7

                Hi, add another \ to every \ you have in the connectionstring. Hope this one can help Thanks

                G 1 Reply Last reply
                0
                • S SayreCC

                  Hi, add another \ to every \ you have in the connectionstring. Hope this one can help Thanks

                  G Offline
                  G Offline
                  Gindi Bar Yahav
                  wrote on last edited by
                  #8

                  i have tried it before, it dosent do any change, becuse i added @ before the connection string.

                  Gindi Bar Yahav - Web & Software defeloper.

                  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