0

... string EndPointUri { get; set; } = "https://localhost:8081"; string PrimaryKey { get; set; } = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";

    string DBname { get; set; } = AppUser.DatabaseId;//"wenwang0db";
    CosmosClient Cosmos_Client = null;
    Database WenWangDB = null;

    public async Task StartAccessCosmosDataBase()
    {
        DatabaseResponse response;
        ContainerBase<AppUser>.Partition_Key =
        new Microsoft.Azure.Cosmos.PartitionKey( User_Service.TheUser.appUser.GeoLocation.Country );

        if(Cosmos_Client == null )
        {
            try
            {
                Cosmos_Client = new CosmosClient(EndPointUri, PrimaryKey);
                try
                {
                    response = await Cosmos_Client.CreateDatabaseIfNotExistsAsync( DBname );
                    WenWangDB = response.Database;  
                }
                catch( CosmosException cre )
                {
                    Debug.WriteLine(cre.ToString());
                }
            }
            catch( CosmosException cre ) 
            {
                Debug.WriteLine(cre.ToString());
            }
            catch (Exception e)
            {
                Exception baseException = e.GetBaseException();
                Debug.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
            }

        }
        
    }

...

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 28 '22 at 03:16
  • 1. I debug Xamarin.Forms App. on Win11 with Android Emulator to access local Cosmos DB Emulator. 2. Cosmos Client has created Ok. 3. Upon to create named "wenwang0db" Database... the response = await Cosmos_Client.CreateDatabaseIfNotExistsAsync( DBname ) return response = null; 4. program skip 2 catch ( CosmosException )...fall into the last catch (Exception e) with e.Message = "Network subsystem is down".... Many thanks for your response – 王興業 Sep 28 '22 at 04:33
  • Debug on VS2022 and "wenwang0db" has already created on running local Cosmos Emulator, Cosmos Client has created Ok in program – 王興業 Sep 28 '22 at 05:09

0 Answers0