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. Database & SysAdmin
  3. Database
  4. connection string

connection string

Scheduled Pinned Locked Moved Database
databasesysadminsecuritytoolsquestion
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.
  • L Offline
    L Offline
    LiYS
    wrote on last edited by
    #1

    Hi all, I have a .sql script file and wanted to use the following code to write it into one of the database. How should I configure the connection string? I'm new to database programming. using System.Data.SqlClient; using System.IO; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Smo; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string sqlConnectionString = "Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True"; FileInfo file = new FileInfo("C:\\myscript.sql"); string script = file.OpenText().ReadToEnd(); SqlConnection conn = new SqlConnection(sqlConnectionString); Server server = new Server(new ServerConnection(conn)); server.ConnectionContext.ExecuteNonQuery(script); } } }


    G 1 Reply Last reply
    0
    • L LiYS

      Hi all, I have a .sql script file and wanted to use the following code to write it into one of the database. How should I configure the connection string? I'm new to database programming. using System.Data.SqlClient; using System.IO; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Smo; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string sqlConnectionString = "Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True"; FileInfo file = new FileInfo("C:\\myscript.sql"); string script = file.OpenText().ReadToEnd(); SqlConnection conn = new SqlConnection(sqlConnectionString); Server server = new Server(new ServerConnection(conn)); server.ConnectionContext.ExecuteNonQuery(script); } } }


      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      Here you are: http://connectionstrings.com/[^]

      Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

      L 1 Reply Last reply
      0
      • G Giorgi Dalakishvili

        Here you are: http://connectionstrings.com/[^]

        Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

        L Offline
        L Offline
        LiYS
        wrote on last edited by
        #3

        I used the following string: "Driver={SQL Native Client};Server=MACHINE_NAME\\SQLEXPRESS ;Database=C:\\tset.mdf;"; but ended up with exception saying "Driver" is an unsupported keyword and when I removed this keyword the unhandled exception occurred.


        G 1 Reply Last reply
        0
        • L LiYS

          I used the following string: "Driver={SQL Native Client};Server=MACHINE_NAME\\SQLEXPRESS ;Database=C:\\tset.mdf;"; but ended up with exception saying "Driver" is an unsupported keyword and when I removed this keyword the unhandled exception occurred.


          G Offline
          G Offline
          Giorgi Dalakishvili
          wrote on last edited by
          #4

          You should use the one SqlConnection (.NET) section

          Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

          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