Subject: Chapter 12 SQL Server Access
Posted By: crazy Post Date: 9/17/2003 1:07:24 PM
In this useless wrox press book I'm currently being tortured by there is the script below, it is suppose to simply open and close a connection to SQL Server 2000 but it doesn't work:

<%@Import namespace="System.Data"%>
<%@Import namespace="System.Data.SqlClient"%>
<script runat="server" language="c#">
void Page_Load()
{
      string strConnection = "user id=sa;password=;";
      strConnection += "initial catalog=northwind;server=MIKE;";
      strConnection += "Connect Timeout=30";
     
      data_src.Text = strConnection;
 
     SqlConnection objConnection = new SqlConnection(strConnection);
  
     try
     {
          objConnection.Open();
          con_open.Text = "Connection opened successfully.<br />";
          objConnection.Close();
          con_close.Text = "Connection closed <br />";
     }
     catch (Exception e)
     {
         con_open.Text = "Connection failed to open.<br />";
         con_close.Text = e.ToString();
     }
}
</script>
<html>
<body>
<h4>Testing the data connection <asp:label id="data_src" runat="server" /></h4>
<asp:label id="con_open" runat="server" /><br />
<asp:label id="con_close" runat="server" /><br />
</body>
</html>

It returns the following error:

System.Data.SqlClient.SqlException: Login failed for user 'sa'. at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) at System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) at System.Data.SqlClient.SqlConnection.Open() at ASP.sql_connection_aspx.Page_Load()

The book also states that if the code doesn't work we should try replacing the user id and password line with this line:

string strConnection = "Integrated Security=SSPI;";

But this doesn't work either. So needless to say I have no idea what's wrong, can anyone help as unfortunately the psychic powers Wrox Press clearly believe I possess aren't working. I have no idea whether this should work straight out like this or whether some configuration or something needed to be done first. I'm totally stuck, please help.

Reply By: crazy Reply Date: 9/20/2003 8:59:01 AM
Ok, I have the answer so there is no need to respond. If anyone is interested you can't use the sa account if you're using SQL Server 2000 (as I am), as a password is automatically generated for this account by SQL Server 2000 (and I have no idea what it is). In previous SQL Server versions this wasn't the case. So if you're using SQL Server 2000 you should create a new user, and use that user id and password in place of the one in the example.


Go to topic 4352

Return to index page 1042
Return to index page 1041
Return to index page 1040
Return to index page 1039
Return to index page 1038
Return to index page 1037
Return to index page 1036
Return to index page 1035
Return to index page 1034
Return to index page 1033