Link to home
Start Free TrialLog in
Avatar of sydneyguy
sydneyguyFlag for Australia

asked on

getting an aspx page to access a sqlserver data base

am running this code but is throwing up an error

An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

have been through to
Enable remote connections for SQL Server 2005 Express or SQL Server 2005 Developer Edition
and
Enable the SQL Server Browser service
but still gives me an error

 Response.Write("sql update")
                Dim MyConnection As SqlConnection
            MyConnection = New SqlConnection("server=(PER-148\SQLEXPRESS)\;database=TechKnowBaseSQL;Trusted_Connection=yes")
                Dim DS As DataSet
                Dim MyCommand As SqlDataAdapter
               
            MySql = "SELECT SearchName FROM tblsearchname"
               
            MyCommand = New SqlDataAdapter(MySql & "ORDER BY SearchName", MyConnection)
            Try
                DS = New DataSet()
                MyCommand.Fill(DS, "tblsearchname")
                MyDataGrid.DataSource = DS.Tables("tblsearchname").DefaultView
                MyDataGrid.DataBind()
            Catch
                ErrBox.Text = "Err 1005 xxxxxzzz Could not Update Data Grid Check if SQL DataBase Operational"
            End Try
            MyConnection.Close()
Avatar of dqmq
dqmq
Flag of United States of America image

Lots of problems can cause that error.  My guess is that the IIS account that is serving the ASP page does not have permission to login to SQL Server or the login does not have permissions to access the TechKnowBaseSQL database.

Often in this scenario, you want to go like this.   Enable SQL authentication.  Create an SQL Server login dedicated to your ASP site and give it the necessary permissions for the TechKnowBaseSQL database.  Make sure you can login from SSMS using that login. Change your connection string from Trusted connection to one with UID and PWD.
Avatar of sydneyguy

ASKER

have set up the un and password for techknowbase but how do i check using ssms please to check that its workign ok
new connection string

 MyConnection = New SqlConnection("server=(PER-148\SQLEXPRESS)\;database=TechKnowBaseSQL; User Id=admin; password=admin1") ''admin admin1
>how do i check using ssms
Start SSMS from any workstation
Click the Options button
On the login tab
   Enter Server name: PER-148\SQLEXPRESS
   Choose SQL Authentication
   Enter Userid and Password that you setup
On the Connection Propeties tab
   Enter the database name

Click the Connect button


Do you connect?
have ssms (sql server management studio )
weres the options button please
ok found the login in form the main connection rgt click have tested it and set it up and it works fine
but when i go to acceess the tables it throws up the below error see image
error.png
User generated image
still throws up
An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

User generated image
its a log in issue but cannot see what it is
Because you can see the Object Explorer tells me that your login is connecting to the server.  The next step is to diagnose why you are having difficulty accessing the database.

1.  On the above screen shot, click the User Mapping page (on the right side) to see what database are mapped

2.  Also, under databases on the left side, expand security, then users to see what users are defined for the TechKnowBaseSQL database.
User generated image
User generated image
User generated image
login in through ssms using admin admin1 as un and pw and it worked fine use a diff pw and it fials so thats workign ok
ASKER CERTIFIED SOLUTION
Avatar of dqmq
dqmq
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks for you help up and running now