locked
connecting to sql server 2005 RRS feed

  • Question

  • I am using visual studio 2005 and sql server 2005. It seems that I can not connect to the sql server from my mobile application. it always return "the sql server not found" error message. i think its not the code problem, because i try exactly the same code and connection string on windows application and i dont have any problem,anyway what i was trying to do is just a simple as showing the table from my database. but the error makes me crazy.

    so i was thinking is there anything that i need to install or include in my program so that i can connect to the sql server from my mobile?

    thanks.

    Friday, May 7, 2010 9:11 AM

Answers

  • Hi siEricko,

    We just code like desktop, like the code below:

    using System.Data.SqlClient;

        string connString = "Data Source=<servers address>,<port if necessary>;Initial Catalog=SqlTestDb;User Id=id;Password=pwd;";

        string cmdText = "select Id, Name from Customers";

        using (SqlConnection conn = new SqlConnection(connString))

        {

            conn.Open();

            SqlCommand cmd = new SqlCommand(cmdText, conn);

            SqlDataReader reader = cmd.ExecuteReader();

     

            while (reader.Read())

            {

                System.Diagnostics.Debug.WriteLine(string.Format("{0}, {1}", reader[0], reader[1]));

            }

            reader.Close();

        }

     

    For more information:
     How do I connect to a desktop SQL Server database? 


    Best regards,
    Guang-Ming Bian - MSFT


    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Tuesday, May 11, 2010 9:32 AM