header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Adding Multiple query
Last Post 08 Sep 2009 11:52 PM by ananda. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
anandaUser is Offline
New Member
New Member
Posts:28
Avatar

--
08 Sep 2009 03:52 AM
    Hi friends,

    I want ask two doubts, In powershell script

    1. $con = "server=ipaddress;database=master;Integrated Security=true"

    Error
    Exception calling "Fill" with "1" argument(s): "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection."

     $con = "server=ipaddress;database=master;Integrated Security=true" - This statment require local Administrator login for execute the query,  some of the server this login has been disabled. so how can i change connection string? but i did't know sa password

    2.

    $con = "server=ipaddress;database=master;Integrated Security=true"
      $cmd="SELECT * from tablename" 
      $da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $con)
      $dt = new-object System.Data.Datatable
      $da.fill($dt)
      $svr
    $Reslut = $dt| out-string

    I want adding multiple query, how can change it? for exmple
      $cmd="SELECT * from tablename1" 
    $cmd="SELECT * from tablename2" 

    Thanks
    Chad MillerUser is Offline
    Basic Member
    Basic Member
    Posts:160
    Avatar

    --
    08 Sep 2009 09:50 AM
    1. Changing the connection string to sa won't help you if you don't know the password. I would suggest looking at two things:
    Adding your login to the SQL instance by running SSMS as a local administrator
    Ensuring allow remote connection options is turned on. By default MSDE/Express versions this option off and you will not be allow to connect removely.
    As far as connection strings, check out http://connectionstrings.com/ for sample connection strings.

    2. This works fine for me as far as executing two queries, do you want to execute both queries in a single pass?

    $con = "server=ipaddress;database=master;Integrated Security=true"
    $cmd="SELECT * from tablename1"
    $da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $con)
    $dt = new-object System.Data.Datatable
    $da.fill($dt)
    $Reslut = $dt| out-string

    $cmd="SELECT * from tablename2"
    $da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $con)
    $dt = new-object System.Data.Datatable
    $da.fill($dt)
    $Reslut = $dt| out-string
    anandaUser is Offline
    New Member
    New Member
    Posts:28
    Avatar

    --
    08 Sep 2009 11:52 PM

    Hi Cmile thanks for your reply.

    #1 - I have created one sql user and given permission to respective database,  and changed connection string also It is worked for me.
    $con = "server=ipaddress;database=master;User Id=username;Password=password"

    #2 As per your reply that is also worked fine for me

    Thanks

     

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer