Error "Login failed for user ..."

F

fl

I am running ASPNET on my local machine. I have a problem when I try to
connect to a SQL server database table. The data looks good when I right
click SqlDataAdapter1 to preview the data. When F5 to run it, I get this
error "Login failed for user '(null)'. Reason: Not associated with a
trusted SQL Server connection..."

Here is my code (they are all generated by the wizard):

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.DataSet11 = New connectToDatabase.DataSet1
CType(Me.DataSet11,
System.ComponentModel.ISupportInitialize).BeginInit()
'
'SqlDataAdapter1
'
Me.SqlDataAdapter1.InsertCommand = Me.SqlInsertCommand1
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
Me.SqlDataAdapter1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "sav_customer", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("ctct_SER_ID", "ctct_SER_ID"), New
System.Data.Common.DataColumnMapping("ctct_ID_RSSD", "ctct_ID_RSSD"),
New System.Data.Common.DataColumnMapping("CTCT_LVL_CD",
"CTCT_LVL_CD")})})
'
'SqlInsertCommand1
'
Me.SqlInsertCommand1.CommandText = "INSERT INTO
dbo.sav_customer(ctct_SER_ID, ctct_ID_RSSD, CTCT_LVL_CD) VALUES (@ctc" &
_
"t_SER_ID, @ctct_ID_RSSD, @CTCT_LVL_CD); SELECT ctct_SER_ID,
ctct_ID_RSSD, CTCT_L" & _
"VL_CD FROM dbo.sav_customer"
Me.SqlInsertCommand1.Connection = Me.SqlConnection1
Me.SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@ctct_SER_ID",
System.Data.SqlDbType.VarChar, 8, "ctct_SER_ID"))
Me.SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@ctct_ID_RSSD",
System.Data.SqlDbType.Int, 4, "ctct_ID_RSSD"))
Me.SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@CTCT_LVL_CD",
System.Data.SqlDbType.VarChar, 2, "CTCT_LVL_CD"))
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "workstation
id=K1FZL00D0;packet size=4096;integrated security=SSPI;data source=nt" &
_
"assql18;persist security info=False;initial catalog=Sadstat"

'
Me.SqlSelectCommand1.CommandText = "SELECT ctct_SER_ID,
ctct_ID_RSSD, CTCT_LVL_CD FROM dbo.sav_customer WHERE (CTCT_L" & _
"VL_CD = '1') AND (ctct_SER_ID = 'FR2900')"
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
'
'DataSet11
'
Me.DataSet11.DataSetName = "DataSet1"
Me.DataSet11.EnforceConstraints = False
Me.DataSet11.Locale = New
System.Globalization.CultureInfo("en-US")
CType(Me.DataSet11,
System.ComponentModel.ISupportInitialize).EndInit()

End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents SqlDataAdapter1 As
System.Data.SqlClient.SqlDataAdapter
Protected WithEvents SqlSelectCommand1 As
System.Data.SqlClient.SqlCommand
Protected WithEvents SqlInsertCommand1 As
System.Data.SqlClient.SqlCommand
Protected WithEvents SqlConnection1 As
System.Data.SqlClient.SqlConnection
Protected WithEvents DataSet11 As connectToDatabase.DataSet1
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
SqlDataAdapter1.Fill(Me.DataSet11)
DataGrid1.DataSource = DataSet11
DataGrid1.DataBind()
End Sub


End Class

I have check the security setting under C:\Inetpub\wwwroot\. I have
tried to tweak around the connection strings. I don't know what else to
check. I would appreciate any input. Thanks.
 
M

Mark Fitzpatrick

When trying to connect from an editor such as Visual Studio, you are using
your own user account. When trying to connect from a web page, the ASPNET
user account will be the one accessing the db. By default no anonymous
account is mapped onto a SQL Server user account. You can map the ASPNET
user account to a SQL Server user account inside SQL Server, but this isn't
a good idea if you aren't going to contorlthe server this is hosted on (and
also makes a possible security hazard). Your best bet is to use an actual
SQL Server login and pass that in the connection string as it's the easiest
thing to deploy in most scenarios.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP- FrontPage
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top