コード例 #1
0
        public string getConnectionStringForAzureDbService(string serviceTypeName, string serviceInstanceName = "", IDbConnectionStringFormatter formatter = null)
        {
            string connectionString = null;

            if (Object.ReferenceEquals(null, vcap_services_data) == false)
            {
                dynamic serviceInfo = getInfoForService(serviceTypeName, serviceInstanceName);

                if (Object.ReferenceEquals(null, serviceInfo) == false)
                {
                    var cstring = Convert.ToString(serviceInfo.credentials.connectionstring);
                    if (string.IsNullOrEmpty(cstring))
                    {
                        // Default to use a Basic MS SQL Server connection string, if our formatter was not specified.
                        if (formatter == null)
                        {
                            formatter = new BasicSQLServerConnectionStringFormatter();
                        }

                        var host     = Convert.ToString(serviceInfo.credentials.sqlServerFullyQualifiedDomainName);
                        var username = Convert.ToString(serviceInfo.credentials.databaseLogin);
                        var password = Convert.ToString(serviceInfo.credentials.databaseLoginPassword);
                        //var port = Convert.ToString(serviceInfo.credentials.port);
                        var databaseName = Convert.ToString(serviceInfo.credentials.sqldbName);

                        connectionString = formatter.Format(host, username, password, databaseName, "1433");
                    }
                    else
                    {
                        connectionString = cstring;
                    }
                }
            }
            return(connectionString);
        }
コード例 #2
0
        public string getConnectionStringForDbService(string serviceTypeName, string serviceInstanceName = "", IDbConnectionStringFormatter formatter = null)
        {
            string connectionString = "";

            if (Object.ReferenceEquals(null, vcap_services_data) == false)
            {
                dynamic serviceInfo = getInfoForService(serviceTypeName, serviceInstanceName);

                if (Object.ReferenceEquals(null, serviceInfo) == false)
                {
                    // If there's a connection string defined, return that directly and do not build a connection string
                    var cstring = Convert.ToString(serviceInfo.credentials.connectionstring);
                    if (string.IsNullOrEmpty(cstring))
                    {
                        // Default to use a Basic MS SQL Server connection string, if our formatter was not specified.
                        if (formatter == null)
                        {
                            formatter = new BasicSQLServerConnectionStringFormatter();
                        }

                        var host         = Convert.ToString(serviceInfo.credentials.hostname);
                        var username     = Convert.ToString(serviceInfo.credentials.username);
                        var password     = Convert.ToString(serviceInfo.credentials.password);
                        var port         = Convert.ToString(serviceInfo.credentials.port);
                        var databaseName = Convert.ToString(serviceInfo.credentials.name);

                        connectionString = formatter.Format(host, username, password, databaseName, port);
                    }
                    else
                    {
                        connectionString = cstring;
                    }
                }
            }
            return(connectionString);
        }