Monday, March 19, 2012

Clue - Who dun it? The Data Adapter, DataSet, SqlSelect etc...

Ok, I know my connection string and config file are good. Once the rest of the code is added I receive this error:

"SQL Server does not exist or access denied. "

I'm using the 1.1 framework and my hosting company provides MSSql 2005.

Thanks for your time,

Charlie

Here's the code in my cond behind file.

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

namespace blog

{

/// <summary>

/// Summary description for WebForm1.

/// </summary>

public class WebForm1 : System.Web.UI.Page

{

protected System.Data.SqlClient.SqlConnection sqlConnect;

protected System.Web.UI.WebControls.DataList dList;

protected System.Data.SqlClient.SqlDataAdapter DA;

protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;

protected System.Web.UI.WebControls.LinkButton linkAdmin;

protected System.Web.UI.WebControls.Image header;

protected blog.DS ds1;

private void Page_Load(object sender, System.EventArgs e)

{

DA.Fill(ds1, "blogEntry");

dList.DataBind();

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.sqlConnect = new System.Data.SqlClient.SqlConnection();

this.DA = new System.Data.SqlClient.SqlDataAdapter();

this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();

this.ds1 = new blog.DS();

((System.ComponentModel.ISupportInitialize)(this.ds1)).BeginInit();

this.linkAdmin.Click += new System.EventHandler(this.linkAdmin_Click);

//

// sqlConnection String

//////////////////webserver////////////////

this.sqlConnection1.ConnectionString = "Server=xxx.xxx.xxx.x;Database=myDataBase;User ID=myID;Password=myPass";

//////////////////local///////////////////

//this.sqlConnect.ConnectionString = "workstation id=HAL;packet size=4096;integrated security=SSPI;data source=HAL;pers" +

//"ist security info=False;initial catalog=blog";

//

// DA

//

this.DA.SelectCommand = this.sqlSelectCommand1;

this.DA.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {

new System.Data.Common.DataTableMapping("Table", "blogEntry", new System.Data.Common.DataColumnMapping[] {

new System.Data.Common.DataColumnMapping("bodyID", "bodyID"),

new System.Data.Common.DataColumnMapping("linkID", "linkID")})});

//

// sqlSelectCommand1

//

this.sqlSelectCommand1.CommandText = "SELECT id, wxID, dateID, titleID, bodyID, linkID FROM blogEntry ORDER BY id DESC";

this.sqlSelectCommand1.Connection = this.sqlConnect;

//

// ds1

//

this.ds1.DataSetName = "DS";

this.ds1.Locale = new System.Globalization.CultureInfo("en-US");

this.Load += new System.EventHandler(this.Page_Load);

((System.ComponentModel.ISupportInitialize)(this.ds1)).EndInit();

}

#endregion

private void linkAdmin_Click(object sender, System.EventArgs e)

{

Server.Transfer("logOn.aspx",true);

}

}

}

fatthippo:

Ok, I know my connection string and config file are good. Once the rest of the code is added I receive this error:

"SQL Server does not exist or access denied. "

If you are receiving that error, it generally means that your connection string is NOT good. Check out this KB article:Potential causes of the "SQL Server does not exist or access denied" error message.

|||

That string was pasted in from another page on the same host. It works fine there. Why should I not assume that it's good?

|||

Hello,

Something I just noticed in the stack trace.

 
 blog.WebForm1.Page_Load(Object sender, EventArgs e)in c:\inetpub\wwwroot\blog\index.aspx.cs:31

 this is still referencing my local machine. How can I change this?
  

|||

Hi,

From your code, I can see your connection string is:

Server=xxx.xxx.xxx.x;Database=myDataBase;User ID=myID;Password=myPass

Please check if your server address is correct. Is the SQL server you're connecting to a default instance or a named instance. If a named instance, please try to use Server=xxx.xxx.xxx.xxx\InstanceName

also, please check the login name and password. You can try to create a .udl file for testing. Here are the steps:

1. Create a Text file.
2. Rename it to .udl
3. Double click on the file, and test in the Data Link Properties window.

HTH.

|||

I believe I found the issue. This being my first attempt to host a .net web app on a ISP, it didn't occur to me that modifying the connection string in the provided online text editor wouldn't be sufficient. Simply put, I needed to recompile my app.

Thank-you all for your support.

Fatthippo

No comments:

Post a Comment