Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

getting an aspx page to access a sqlserver data base

Posted on 2012-03-09
17
Medium Priority
?
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

715 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