none
TCP Provider, error: 0 - An invalid argument was supplied (Code working in web application, but not in windows form) RRS feed

  • Question

  • Hi Team,

    I have created a Windows project and Web project, trying to execute sql query.

    Im succeed for web application, but same code is not working in windows form.

    OS: Windows 7

    DB: Sql server 2005

    IDE: VS 2008

    Error: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - An invalid argument was supplied.)

    Source code:

    Dim sqlConn As New SqlConnection
            sqlConn.ConnectionString = "Data Source=XXXXX;Initial Catalog=XXXX;Integrated Security=True"

            Try
                Dim cmdSQL As New SqlCommand()
                cmdSQL.CommandType = Data.CommandType.Text
                cmdSQL.CommandText = "SELECT  *FROM dbo.SecuCode"
                cmdSQL.Connection = sqlConn

                Dim adptSQL As New SqlClient.SqlDataAdapter(cmdSQL)
                Dim myDataSet As New DataSet()
                adptSQL.Fill(myDataSet)

                sqlConn.Close()
                MessageBox.Show("Test successful")

            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try

    • Moved by Bob Beauchemin Thursday, November 20, 2014 5:24 PM Moved to the forum for client-side SqlClient provider issues
    • Moved by Fred BaoModerator Friday, November 21, 2014 3:31 AM
    Thursday, November 20, 2014 11:50 AM

All replies

  • The error means that you were not able to find the SQL Server you are connecting to. This could be because of firewalls, spelling errors, SQL Server not running or any number of things. You will need to troubleshoot your environment.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    Thursday, November 20, 2014 2:00 PM
  • How is this an EF issue? It should be moved to the below forum.

    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?category=sqlserver

    Thursday, November 20, 2014 10:11 PM
  • Hi Erland,

    Thanks for your response.

    Source code including db connection is working as excepted in .aspx web form, issue in winform .vb only.

    Could you please assist on this.

    Thank you.

    Friday, November 21, 2014 3:50 AM
  • Hello Peddi,

    Do you solve this issue? If it is, I suggest that you could share your solutions & experience here. It will be very beneficial for other community members who have similar questions.

    If not, with your provided code, I made a test, however, it could work as expected, so the code should be ok, I am wondering if the environment is not configured correctly, you could check this blog to troubleshooting the connect error:

    http://blogs.msdn.com/b/sql_protocols/archive/2006/09/30/sql-server-2005-remote-connectivity-issue-troubleshooting.aspx?PageIndex=4

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 28, 2014 7:34 AM
    Moderator
  • your error is specifically about your SQL connection string.. verify that your connection string is  correct so the connection into your database from where your project will not return a an Invalid argument exception error.. 
    Sunday, January 18, 2015 8:36 AM