1 Attachment(s)
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,.
Re: sql server, database stored procedure not working with ip address, please help.
Quote:
Originally Posted by
sujan.dasmahapatra
...
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)?