CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    164

    sql server, database stored procedure not working with ip address, please help.

    Dear folks.

    I am writing a program for connecting sql server database, and populating data from table using a stored procedure. it is working fine when I use the app.config file's data source as the server name, but when I use the server's ip address and port, it is not working.

    it is showing error, stored procedure not found.

    My app config's connection string is as below.
    Code:
    <connectionStrings>  
          <clear />  
          <add name="CONNECTION_FLOR"
           providerName="Microsoft.Data.SqlClient"
           connectionString="Data Source=172.142.1.100,1433;User ID=pregit;Password=shois87;Initial Catalog=tempdb;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" />  
          </connectionStrings>
    But when I use Data Source by name as Data Source=(localdb)\SubdivprojV13; it is working all good. The problem is with ip address and port. I checked the connection, connection is opening. But showing error as stored procedure not found.


    please check my code snippet.
    Code:
    Public Class Form1
        Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("CONNECTION_FLOR").ConnectionString)
        Private Sub BTN_DISPLAY_Click(sender As Object, e As EventArgs) Handles BTN_DISPLAY.Click
            Dim cmd As New SqlCommand With {
                .Connection = connection,
                .CommandType = CommandType.StoredProcedure,
                .CommandText = "SP_DISPLAY"
            }
            cmd.Connection.Open()
            lbl_CONN.Text = "Connected"
            lbl_CONN.ForeColor = Color.Green
    
            Dim dt As DataTable = New DataTable()
            dt.Load(cmd.ExecuteReader)
            DataGridView1.DataSource = dt
            DataGridView1.Update()
    
            If connection.State = ConnectionState.Open Then
                connection.Close()
                lbl_CONN.Text = "DisConnected"
                lbl_CONN.ForeColor = Color.Red
            End If
        End Sub
    End Class
    The error I am getting is in attachment, you can see connection is connected, but the stored procedure is not found.

    Any help is highly appreciated. Thanks in advance,.
    Attached Images Attached Images  
    Last edited by VictorN; April 12th, 2021 at 11:52 AM. Reason: adding CODE tags

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: sql server, database stored procedure not working with ip address, please help.

    Quote Originally Posted by sujan.dasmahapatra View Post
    ...
    it is showing error, stored procedure not found.

    My app config's connection string is as below.
    Code:
    <connectionStrings>  
          <clear />  
          <add name="CONNECTION_FLOR"
           providerName="Microsoft.Data.SqlClient"
           connectionString="Data Source=172.142.1.100,1433;User ID=pregit;Password=shois87;Initial Catalog=tempdb;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" />  
          </connectionStrings>
    Why do you set the tempdb as the Initial Catalog (Database)?
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured