C# .NET med SQL - Fejl imellem side og database
Hej... Jeg er lige begyndt at rode med noget C# .Net. Jeg har det problem, at jeg hverken kan læse fra / skrive til min database. Hvis jeg vil læse fra databasen får jeg denne fejlmeddelelse: Login failed for user 'f33933'. Reason: Not associated with a trusted SQL Server connection.Jeg bruger dette til at connecte til serveren:
<add key="SQLcon" value="data source=DKDN01XX24;initial catalog=Jakob;password=********;persist security info=True;user id=f33933;workstation id=w74607;packet size=4096" />
Jeg har 2 buttons som skal hente og skrive til databasen.
Min kode:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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.Configuration;
using System.Data.SqlTypes;
namespace projekt
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label testLabel;
protected System.Web.UI.WebControls.Label Labeltest;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.TextBox output;
protected System.Web.UI.WebControls.TextBox Input;
protected System.Web.UI.WebControls.ListBox ListBox1;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#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.Input.TextChanged += new System.EventHandler(this.TextBox1_TextChanged);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.output.TextChanged += new System.EventHandler(this.TextBox2_TextChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
string barcode;
barcode = Input.Text.ToString();
testLabel.Text = barcode;
string SQLconStr = ConfigurationSettings.AppSettings["SQLcon"];
SqlConnection DB_Connection = new SqlConnection(SQLconStr);
SqlDataAdapter StepAdapter = new SqlDataAdapter("INSERT INTO Jakob (barcode) VALUES('"+ barcode +"')", DB_Connection);
}
private void TextBox1_TextChanged(object sender, System.EventArgs e)
{
}
private void TextBox5_TextChanged(object sender, System.EventArgs e)
{
}
private void TextBox2_TextChanged(object sender, System.EventArgs e)
{
}
private void Button2_Click(object sender, System.EventArgs e)
{
string SQLconStr = ConfigurationSettings.AppSettings["SQLcon"];
SqlConnection DB_Connection = new SqlConnection(SQLconStr);
SqlDataAdapter StepAdapter = new SqlDataAdapter("SELECT * FROM Jakob ORDER BY filename asc", DB_Connection);
DataSet FileList = new DataSet();
StepAdapter.Fill(FileList, "FileListSet");
ListBox1.DataSource = FileList;
ListBox1.DataMember = "FileListSet";
ListBox1.DataTextField = "barcode";
ListBox1.DataBind();
}
}
}
