title: how to use VB.NET to connect to sql server with user 'sa' and restore a database
body: <p>I am new to VB.NET, and needed some help to make a connection to sql server.</p>
  
  <p>I instralled sql server 2008 r2 express with instance name "sqlexpress", and passowrd "sql123".</p>
  
  <p>I need to create a connection to this server instance, with user 'sa', and restore my .bak database file. 
  After this I thought to create a new user with name and password 'inituser', only for this database, running a T-SQL query with VB.NET.</p>
  
  <p>This is my initial function:</p>
  
  <pre><code>Private Sub DBConnect()
      Dim myConn As SqlConnection
      Dim q1 As SqlCommand
      Dim q2 As SqlCommand
  
      myConn = New SqlConnection(@"Server=.\SQLEXPRESS;User Id=sa;Password=sqlexpress1;")
      ' restore the databse .bak file
      q1 = myConn.CreateCommand
      q1.CommandText = "RESTORE DATABASE AdventureWorks2012 FROM DISK = '" + _DBFilePath + "'"
      ' create new user for EasyFarmacy Database
      q2 = myConn.CreateCommand
      q2.CommandText = "CREATE LOGIN inituser WITH PASSWORD = 'inituser' USE EasyFarmacy GO CREATE USER inituser FROM login inituser GO"
  
      Try
          myConn.Open()
          q1.ExecuteNonQuery()
          q2.ExecuteNonQuery()
      Catch ex As Exception
          MsgBox("Database connection error!  + '" + ex.Message + "'")
      End Try
      myConn.Close()
  End Sub
  </code></pre>
  
  <p>Can anyone help me?</p>