Solved

getting an aspx page to access a sqlserver data base

Posted on 2012-03-09
17
228 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now