Hello, the first question is, how do iknow if the SQLEXPRESS server that in my machine is work well? i have sqlExpress and i also have the sql studio management, i am creating database and tables and all works fine. but when im tryin to call to a database from visual studio the connection failed. (only with sql, with odbc, oledb with access files i get the connection).
the second question, If im writting some winform app and use the connection string Data Source=My server name (for example), How the app will work on some other machine? cause the server name is diffrent no? (i know its sound a little weired but im new in C# development and Databases {Still student}).

1) How are you trying to connect to the SQL Server inside of Visual Studio? You should be using a SQL Native connection

2) You need to create a "SQL Connection Form" in your application that lists the SQL Server and Databases and lets a user select where they want to connect. This is a little technical but you need it for flexibility.

1) How are you trying to connect to the SQL Server inside of Visual Studio? You should be using a SQL Native connection

2) You need to create a "SQL Connection Form" in your application that lists the SQL Server and Databases and lets a user select where they want to connect. This is a little technical but you need it for flexibility.

1) im tryin to connect via the "Add new data connection" i choose the provider, and browse the MDF file when i click test connection its failed. i also try with website project to create the login system (wich create database automaticlly and its failed) somehow he can make connection to sql database, even if im tryin to make in VS "add new item" and choose "Data base file" before making any connection he cant let me and close the request.

2) what if i want to make app for few offices? and they are not know how to use sql or something about computers? what database can i use that after they make installation they can work with the program without making any computering deals?

2)you know what i mean? like, when you (ok not you, you are developer) someone install software in his computer, the software didn't ask him what sql server to use..... the user make the install and then start working with the program. the program automaticlly save the data somewhere....

With Microsoft SQL Server you typically don't use the .mdf and .ldf files directly, you connect to the SQL Server with named pipes. Here is how you connect in code:

public static string BuildSqlNativeConnStr(string server, string database)
    {
      return string.Format("Data Source={0};Initial Catalog={1};Integrated Security=True;", server, database);
    }
    private void simpleButton1_Click(object sender, EventArgs e)
    {
      const string query = "Insert Into Employees (RepNumber, HireDate) Values (@RepNumber, @HireDate)";

      string connStr = BuildSqlNativeConnStr("apex2006sql", "Leather");
      DataTable dt;
      try
      {
        using (SqlConnection conn = new SqlConnection(connStr))
        {
          conn.Open();
          using (SqlCommand cmd = new SqlCommand(query, conn))
          {
            cmd.Parameters.Add(new SqlParameter("@RepNumber", 50));
            cmd.Parameters.Add(new SqlParameter("@HireDate", DateTime.Today));
            using (SqlDataReader dr = cmd.ExecuteReader())
            {
              dt = new DataTable();
              dt.Load(dr);
            }
          }
        }
        System.Diagnostics.Debugger.Break(); //At this point you have the populated datatable
      }
      catch (SqlException)
      {
        System.Diagnostics.Debugger.Break();
      }
    }

With the designer when you go to setup your connection change the driver to "Microsoft SQL Server (SqlClient)" and hit the servername dropdown. It should find your local instance. Follow the wizard from there.

2) You deploy the SQL Server and have your installer setup the SQL Server so you know the instance name. Then you can connect to the server WORKSTATION\INSTANCE. But you want to give them the ability to switch databases in case you send out a test version of code or they want to test something and not user their live data.

This question has already been answered. Start a new discussion instead.