Hello everyone, I am having problems getting a simple string from a textbox into a SQL Server Express database. Here is what I have:
protected
void Submit_Click(object sender, EventArgs e){
string connection = "Data Source=./SQLEXPRESS;AttachDbFilename=C:/Users/Ryan/Documents/Visual Studio 2005/WebSites/MyQuizAJAX/App_Data/QuizSQL.mdf;Integrated Security=False;Connect Timeout=30;User Instance=True;Asynchronous Processing=true"; SqlConnection newCon = new SqlConnection(connection);newCon.Open();
SqlCommand insertCommand = new SqlCommand("INSERT INTO StatsTable Title VALUES ('test')", newCon);insertCommand.BeginExecuteNonQuery();
}
The code above should enter "test" into the title column in the statstable but I get an error saying I need to enable my SQL Server accept remote connections, any ideas? Am I even approaching this correctly?
Ryan TurneyPosted Oct 15, 2007, 12:05 AM
I've been messing around with this part of my program and I solved the error, but now I cannot get the text from the textbox into my database. Any ideas on why it's not being inserted?
Regarding my connection string, you are correct it is located locally in the App_Data folder. It is being authenticated by windows as well. I'm no expert so I'm not 100% on my connection string. I basically copied and pasted from a SQLDataSource on my web page so right now I'm just kind of diving into this, any recommendations are appreciated.
Scott LyslePosted Oct 14, 2007, 10:32 PM
You may wish to refer to this article: http://support.microsoft.com/default.aspx/kb/914277
The article pertains to the error mentioned. However, I am interested in your connection string; since this is posted under asp.net you are attaching to a local copy of the database and using user instance=true; this works only on a local copy of the database and requires windows authentication and named pipes.