SQL Connection Failure

Welcome Forums General PowerShell Q&A SQL Connection Failure

This topic contains 3 replies, has 2 voices, and was last updated by

 
Keymaster
1 year, 6 months ago.

  • Author
    Posts
  • #71953

    Participant
    Points: 0
    Rank: Member
       $connection = New-object -TypeName System.Data.SqlClient.SqlConnection
       $connection.ConnectionString = "Server=localhost\SQLEXPRESS;Database=admindata;Trusted_Connection=True;"
       $connection.open() 
    

    I am using windows 10 terminal and I have SQL server 2012 Express installed on my laptop. I am practicing the Nugget by Don Jones which is on Uploading information from powershell to SQL server. Problem I am facing is that I am not able to open the connection .Connection object gets created but it is in closed status. If I try to open the connection object using open() method it gives me below error.

    Exception calling "Open" with "0" argument(s): "Arithmetic operation resulted in an overflow."
    At line:1 char:1
    + $connection.Open()
    + ~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : OverflowException

  • #71981

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    I've literally never seen that error in that context.

    If you've not done so, download the SQL Server Management Studio for Express and see if you can connect using that. Also, ensure that the database "admindata" has been created.

    • #72028

      Participant
      Points: 0
      Rank: Member

      Hi Don,

      I am using the SQL Server Management studio 2012 Express as you suggested in the CBT nugget. AdminData database is also already created but still not sure why its not allowing me to connect. I googled a lot but did not find such error anywhere.Mostly people struggle with network based errors but this error is not giving me any clue as to what might be going wrong.

  • #72034

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    Hmm. That's a pretty old version. Older Express had a "user mode" you might be running into. I imagine you're running the shell as admin, but when you use SSMS, you're not admin, correct?

    Could you run a more recent version of Express?

The topic ‘SQL Connection Failure’ is closed to new replies.