0

This is not the first time I have used databases using the C# in asp.net, but I can't seem to make it work in a Winforms app.

This is a test face, so there is not a real database but a SQL Server database file that I created.

What I have is this:

public AddControl SaveResearcher(string name) 
{
   using(SqlConnection conn = new SqlConnection("")){
      SqlCommand cmd = new SqlCommand("INSERT INTO Personell VALUES (@name, @function)", conn);
      cmd.Parameters.Add("name",SqlDbType.VarChar).Value = name;
      cmd.Parameters.Add("function", SqlDbType.VarChar).Value = "Researcher";
      conn.Open();
      cmd.ExecuteNonQuery();
   }

   return AddControl.OK;
}

What do I have to put in the connection string?

Thanks in advance.

4 Answers 4

2

The connection string for at sql server db file without username/password

Server=.\SQLExpress;AttachDbFilename=c:\pathtodb\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;

You may find more connection string options at http://www.connectionstrings.com/sql-server-2008

Sign up to request clarification or add additional context in comments.

Comments

1

You can check there,

Connection strings for SQL Server 2005

Comments

1

Do you mean soemthing like this?

"Data Source[SERVER_NAME];Initial Catalog=[DATABASE_NAME];Integrated Security=True;MultipleActiveResultSets=True"

Comments

0

connectionString="Data Source=computerName\sqlexpress;Initial Catalog=DatabaseName;Integrated Security=True"

1 Comment

If you post code, XML or data samples, PLEASE highlight those lines in the text editor and click on the "code samples" button ( { } ) on the editor toolbar to nicely format and syntax highlight it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.