Solved

getting an aspx page to access a sqlserver data base

Posted on 2012-03-09
17
230 Views
Last Modified: 2012-08-13
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()
0
Comment
Question by:sydneyguy
  • 13
  • 4
17 Comments
 
LVL 42

Expert Comment

by:dqmq
ID: 37704161
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.
0
 

Author Comment

by:sydneyguy
ID: 37704237
have set up the un and password for techknowbase but how do i check using ssms please to check that its workign ok
0
 

Author Comment

by:sydneyguy
ID: 37704240
new connection string

 MyConnection = New SqlConnection("server=(PER-148\SQLEXPRESS)\;database=TechKnowBaseSQL; User Id=admin; password=admin1") ''admin admin1
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 42

Expert Comment

by:dqmq
ID: 37704251
>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?
0
 

Author Comment

by:sydneyguy
ID: 37704262
have ssms (sql server management studio )
weres the options button please
0
 

Author Comment

by:sydneyguy
ID: 37704270
ok found the login in form the main connection rgt click have tested it and set it up and it works fine
0
 

Author Comment

by:sydneyguy
ID: 37704271
but when i go to acceess the tables it throws up the below error see image
error.png
0
 

Author Comment

by:sydneyguy
ID: 37704272
error
0
 

Author Comment

by:sydneyguy
ID: 37704281
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)

sql set up
0
 

Author Comment

by:sydneyguy
ID: 37704283
its a log in issue but cannot see what it is
0
 
LVL 42

Expert Comment

by:dqmq
ID: 37704302
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.
0
 

Author Comment

by:sydneyguy
ID: 37704357
tkb securityuseradmin
0
 

Author Comment

by:sydneyguy
ID: 37704359
usermaping
0
 

Author Comment

by:sydneyguy
ID: 37704362
usermap2
0
 

Author Comment

by:sydneyguy
ID: 37704368
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
0
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 37705063
>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

That all checks out.  Try this connection string:

MyConnection = New SqlConnection()
MyConnection.ConnectionString= "" _
&  "Data Source=PER-148\SQLEXPRESS" _
& ";Initial Catalog=TechKnowBaseSQL" _
& ";User Id=admin" _
& ";password=admin1"
0
 

Author Closing Comment

by:sydneyguy
ID: 37763940
thanks for you help up and running now
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IIS redirect 1 68
ASP.net File format issue in producing Excel file 3 31
Run ColdFusion website locally 1 20
Linq asp.net mvc 13 6
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question