Connect To SQL Database While Using CRM Online RRS feed

  • Question

  • Can anyone tell me how to get data from CRM Online into my SQL Server database? I've searched the web and see that Sandbox access only allows HTTP/HTTPS

    As expected, when I try to connect to my database I get the error saying SqlClient trust failed.

    This is my code:

             string connString =
                    @"Data Source=XXXXXXXXX\XXXXXXX;Initial Catalog=CRMTestingDatabase;" +
                    "User ID = ME; Password = XXXXXXXX";

                SqlConnection _sqlConnection = new SqlConnection(connString);
                SqlCommand _sqlCommand = new SqlCommand();
                _sqlCommand.CommandType = CommandType.StoredProcedure;
                _sqlCommand.CommandText = "usp_InsertContact";

                    //Stored Proc parameters
                    _sqlCommand.Parameters.Add("@FName", SqlDbType.NVarChar).Value = firstname;
                    _sqlCommand.Parameters.Add("@LName", SqlDbType.NVarChar).Value = lastname;
                    _sqlCommand.Parameters.Add("@Add1", SqlDbType.NVarChar).Value = street1;
                    _sqlCommand.Parameters.Add("@Add2", SqlDbType.NVarChar).Value = street2;
                    _sqlCommand.Parameters.Add("@City", SqlDbType.NVarChar).Value = theCity;
                    _sqlCommand.Parameters.Add("@State", SqlDbType.NVarChar).Value = theState;
                    _sqlCommand.Parameters.Add("@Zip", SqlDbType.NVarChar).Value = zipCode;
                    _sqlCommand.Parameters.Add("@Phone", SqlDbType.NVarChar).Value = telePhone;

                    //associate the connection to the command and open
                    _sqlCommand.Connection = _sqlConnection;

                    //execute the Stored Procedure

                catch (Exception ex)

                    throw ex;
                    //Release the connection


    Friday, July 29, 2016 5:32 PM

All replies

  • Hi Fisher,

    I am afraid that CRM online will allow you to connect using  sql connectionstring  due to security issues.

    instead You can use Organization Serive to  perform basic operations like Create, update ,Retrieve etc.

    There are some good samples in the CRM SDK that show how to retrieve data if you are up for writing some C#. This is their intro sample for how to connect to your CRM instance, gather some data, display it, and then update the entities. http://msdn.microsoft.com/en-us/library/hh675400.aspx

    Once you manage to connect to your CRM instance, you will have access to all of your CRM data objects.

    hope this helps

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansarihttp://microxrm.blogspot.in

    Saturday, July 30, 2016 6:44 AM