connect to a sql server Db with c#

Am using the below code to connect to the sqlsever db have not set any passwords or usernames in the dB and am not sure what is supposed to be set or not set to access the db via the C# code any help woudl be appreciated am using visual studio 2005 and sqlserver 2005 when you run the code connection1.Open();
 it just comes back cannot connect
  private void connectsqlserver_Click(object sender, EventArgs e)

            SqlConnection connection1 = new SqlConnection("user id='';" +
                                       "password='';server=serverurl;" +
                                       "Trusted_Connection=yes;" +
                                       "database=Extract; " +
                                       "connection timeout=30");
            SqlCommand insertCommand = new SqlCommand(
                "INSERT INTO tblMainRecInfo (journaltitle) VALUES ('datalkjlkjk')",connection1);
Who is Participating?
hongjunConnect With a Mentor Commented:
try this

SqlConnection connection1 = new SqlConnection(@"Data Source=DICKSMITHMIR-PC\SQLEXPRESS;Initial Catalog=PubMedExtract;Integrated Security=SSPI;");

Open in new window

Pratima PharandeConnect With a Mentor Commented:
connection string like this

  <add name="MyDbConn1"

refr this
sydneyguyAuthor Commented:
is this for c# ?? connection
Increase Security & Decrease Risk with NSPM Tools

Analyst firm, Enterprise Management Associates (EMA) reveals significant benefits to enterprises when using Network Security Policy Management (NSPM) solutions, while organizations without, experienced issues including non standard security policies and failed cloud migrations

Pratima PharandeCommented:
its in web.config of C# project get more details for that link

in code you can use like this

 SqlConnection connection1 = new SqlConnection("Server=MyServer;Database=MyDb;Trusted_Connection=Yes;");
Try this

SqlConnection connection1 = new SqlConnection("Data Source=serverurl;Initial Catalog=Extract;Integrated Security=SSPI;");

Open in new window

Please replace the serverurl with the server name.
sydneyguyAuthor Commented:
SqlConnection connection1 = new SqlConnection("Data Source=DICKSMITHMIR-PC\SQLEXPRESS;Initial Catalog=PubMedExtract;Integrated Security=SSPI;");

this is the connection string but it does not like the DICKSMITHMIR-PC\SQLEXPRESS expecially the \ mark in the equation
sydneyguyAuthor Commented:
that got the local going but will need to lift this up to the sever eventually so thanks for the page link
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.