here are the files guys all I need is to connect my C# app to my sql in server management studio, please help and if possible, please include the step by step on how to do it. Thank you very very much!

Recommended Answers

All 3 Replies

please help me...

According to the attached files, you need:

  • To open the SQL Server Management Studio and connect to your SQLEXPRESS instance.
  • Verify if a database called Project exists. If not, then open the Project.sql file in the root and execute it to create a database called Project.
  • Verify that there is no error and close the SQL Server Management studio.
  • With you VS 2010 Open the sln file in the folder Data Base Project C#. If your PC has a name other than ZACH-PC, you'll need to replace this name in every connString in the project.

Then the database and your project are connected.

Hope this helps

Lightniing this is the 3rd time you've posted this article.

1 - Create your connection string. Get the name of the server you DB is on as well as the name of your DB and add them to your app.config file as shown below.

<connectionStrings>
        <add name="MyConnectionString"
            connectionString="Data Source=**SERVER-NAME-HERE** ;Initial Catalog=**YOUR-DB**;Integrated Security=True"
            providerName="System.Data.SqlClient" />
</connectionStrings>

2 - Create a DB connection method which references your connection string by name (shown below) which you should call when you want to carry out any database functions/ queries etc.

using System.Data.SqlClient;
using System.Configuration;

public SqlConnection Connect()
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString();

            try
            {
                conn.Open();
            }
            catch
            {
            }
            return conn;
        }

You don't need anymore than this to connect to your DB.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.