3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by ChrisHunter
0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.