Please help me, easy question regarding connecting to SQL server. RRS feed

  • Question

  • I developed a windows form application by visual basic 2005. This application is connected to a SQL server 2005 express edition database. I published the application and installed it in the same computer ( let's say " computer A" ) . It worked well. I installed the application in another computer ( let's say " computer B" ). It has SQL server 2005 Express also . The two computers are connected by network adapters.I ran the application in computer B but when I tried to load data in the datagrid , an error message appeared . It says : log on to the server failed."


    The question : How can I run the application in computer B and make it log in to SQL server 2005 Express database in computer A?


    Please help me, I have been working on this problem for 10 days.

    Thanks  a lot.

    Monday, June 25, 2007 10:39 AM

All replies

  • You need to have the proper connection string and make sure that your sql server instance allows remote connections.  I believe by default that sql server 2005 does not accept remote connections.  The setting should be in the surface area configuration utility provided by sql server 2005.  Here is a webpage that contains a lot of connection string info for different databases:
    Monday, June 25, 2007 1:48 PM
  • Thank you very much.


    SQL server express is set to accept remote connections in both computers. Networking the two computers is ok. This is my code:


    Imports System.Data

    Imports System.Data.SqlClient


    Public Class Form1


    Private Sub MealBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MealBindingNavigatorSaveItem.Click




    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim cn As New SqlClient.SqlConnection

    cn.ConnectionString = "Data Source=mishalb\sqlexpress;Initial Catalog=monday;Integrated Security=True;Pooling=False"



    End Sub

    Private Sub OpenSqlConnection()

    Dim connectionString As String = GetConnectionString()

    Using connection As New SqlClient.SqlConnection(connectionString)


    Console.WriteLine("ServerVersion: {0}", connection.ServerVersion)

    Console.WriteLine("State: {0}", connection.State)

    End Using

    End Sub


    Private Function GetConnectionString() As String

    ' To avoid storing the connection string in your code,

    ' you can retrieve it from a configuration file, using the

    ' System.Configuration.ConfigurationSettings.AppSettings property

    Return "Data Source= mishalb\sqlexpress;Database=monday;" _

    & "Integrated Security=SSPI;"

    End Function

    End Class



    But I still have problems. When I run the application in the second computer and try to load data, an error message appears. It says that connection failed, Sql server don't  accept remote connections by default.



    please help me.

    Tuesday, June 26, 2007 10:47 AM
  • Moved to Data Access and Storage fourm as the problem is related to SQL login.


    Mishsad, be sure that the user account on computer B is recognized by computer A, and that the SQL database has been configured to allow the user account.

    Tuesday, June 26, 2007 4:31 PM
  • Tuesday, June 26, 2007 5:51 PM