Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

getting an aspx page to access a sqlserver data base

Posted on 2012-03-09
17
Medium Priority
?
240 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

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

Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

926 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