Solved

getting an aspx page to access a sqlserver data base

Posted on 2012-03-09
17
233 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
Independent Software Vendors: 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 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