Hi Ann, Where did you get that DB conn string from? Aren't you actually trying to connect to your DASP SQL 2005 DB server? If so, please lookover the conn string in your DASP SQL 2005 Control Panel section. Note...You'll be better off making your SQL conns in your web.config rather than the code pages. All the best, Mark
This web application is hosted with DASP.NET but the SQL Server is not. The connection string is accurate. Any other ideas?
I'll do some digging for you. Can definitely remember getting that same error when I tested from within VS 2005 to my local SQL Server. In that case the connection from the same ASP.NET page succeeded to the DASP remote server. So I'm thinking it's a "trust" issue right now.
I appreciate anything you can find. I agree with you. All the other pages I have are using SQL DataSources within the page itself, and those all work fine. These two pages are the only ones where the SQL Code is written in the Code Behind, because I have yet to figure out how to use a SQL DataSource AND the FileUpload Control together. Let me know what you come up with! Thanks!
Hi there. I have an application that has two pages that use file uploads. One uploads a sponsor logo and inserts some information into a table called MM_Sponsors. The other uploads pictures and inserts some information into a tale called MM_Pictures. When I click my button I get the following error message: 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) I am using SQL on other pages in this application and it is working just fine. I only get this error on the pages using the file uploads. Here is the code for the two pages: Imports System.Data.OleDb Imports System.Data Imports System.Data.SqlClient Imports system.IO Partial Class Admin_AdminSponsors Inherits System.Web.UI.Page Dim dbConn As String = 'Data Source=10.10.1.129;Initial Catalog=mcmobilitysyst;Persist Security Info=True;User ID=mcmobilitysyst;Password=*****' Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'must be logged in If Session('logger') <> True Then Response.Redirect('~/adminlogin.aspx') End If End Sub Protected Sub InsertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles InsertButton.Click ' Try Dim FilePathConstant As String = Server.MapPath('\SponsorLogos\') Dim file As Array = Split(FileUpload1.FileName, '\') Dim fi As New FileInfo('\SponsorLogos\' & file(file.Length - 1)) If fi.Exists Then fi.Delete() End If If FileUpload1.FileName <> '' Then FileUpload1.PostedFile.SaveAs(FilePathConstant & file(file.Length - 1)) End If Dim Company As String Dim Website As String Dim FileName As String If FileUpload1.FileName <> '' Then FileName = ''' & file(file.Length - 1) & ''' Else FileName = ''Null.gif'' End If Company = CompanyNameTextBox.Text Company = Replace(Company, ''', '''') Website = WebsiteTextBox.Text Website = Replace(Website, ''', '''') Dim sqlConn As SqlConnection = New SqlConnection(dbConn) Dim sqlCmd As SqlCommand = New System.Data.SqlClient.SqlCommand() Dim sqlAdapter As SqlDataAdapter = New SqlDataAdapter With sqlCmd .Connection = sqlConn .CommandType = CommandType.Text .CommandText = 'Insert into MM_Sponsors (CompanyName, Website, LogoURL) values ('' & Company & '', '' & Website & '', ' & FileName & ')' .Connection.Open() .ExecuteNonQuery() .Connection.Close() End With Response.Redirect('AdminSponsors.aspx') '' Catch ex As Exception 'Label1.Visible = True 'End Try End Sub End Class Imports System.Data.OleDb Imports System.Data Imports System.Data.SqlClient Imports system.IO Partial Class Admin_AdminAddPicturesToGallery Inherits System.Web.UI.Page Dim dbConn As String = 'Data Source=10.10.1.129;Initial Catalog=mcmobilitysyst;Persist Security Info=True;User ID=mcmobilitysyst;Password=boater' Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'must be logged in If Session('logger') <> True Then Response.Redirect('~/adminlogin.aspx') End If End Sub Protected Sub DataList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataList1.SelectedIndexChanged Dim sqlConn As SqlConnection = New SqlConnection(dbConn) Dim sqlCmd As SqlCommand = New System.Data.SqlClient.SqlCommand() Dim sqlAdapter As SqlDataAdapter = New SqlDataAdapter Dim PictureID As String PictureID = DataList1.SelectedValue.ToString With sqlCmd .Connection = sqlConn .CommandType = CommandType.Text .CommandText = 'Delete From MM_Pictures WHERE PictureID = '' & PictureID & ''' .Connection.Open() .ExecuteNonQuery() .Connection.Close() End With Response.Redirect('AdminAddPicturesToGallery.aspx?ID=' & Request.QueryString('ID')) End Sub Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click Try Dim FilePathConstant As String = Server.MapPath('\GalleryImages\') Dim file As Array = Split(FileUpload1.FileName, '\') Dim fi As New FileInfo('\GalleryImages\' & file(file.Length - 1)) If fi.Exists Then fi.Delete() End If If FileUpload1.FileName <> '' Then FileUpload1.PostedFile.SaveAs(FilePathConstant & file(file.Length - 1)) End If Dim Caption As String Caption = CaptionTextBox.Text Caption = Replace(Caption, ''', '''') Dim sqlConn As SqlConnection = New SqlConnection(dbConn) Dim sqlCmd As SqlCommand = New System.Data.SqlClient.SqlCommand() Dim sqlAdapter As SqlDataAdapter = New SqlDataAdapter With sqlCmd .Connection = sqlConn .CommandType = CommandType.Text .CommandText = 'Insert into MM_Pictures (GalleryID, Caption, PictureURL) values ('' & Request.QueryString('ID') & '', '' & Caption & '', '' & file(file.Length - 1) & '')' .Connection.Open() .ExecuteNonQuery() .Connection.Close() End With Response.Redirect('AdminAddPicturesToGallery.aspx?ID=' & Request.QueryString('ID')) Catch ex As Exception Label1.Visible = True End Try End Sub End Class I have built a million pages with file uploads and SQL and this is the first time I have ever had this problem. I am obviously overworked and underpaid and making a very simple mistake. Help!!!!
I think the problem is that your SQL server is not allowing connection from a remote location. I tried telnet to 10.10.1.129 over port 1433 and it is not accepting connection. You should talk to the database administrator housing the DB and ask them to relax the network security to allow remote connection over the Internet. Bruce DiscountASP.NET www.DiscountASP.NET