locked
how to connect sql server with firebase RRS feed

  • Question

  • User-1634604574 posted

    i want to connect sql server with firebase it mean when inserting new row or updating row or deleting row save them in firebase how can i do it?

    Monday, November 25, 2019 7:57 AM

All replies

  • User665608656 posted

    Hi zhyanadil,

    First, create your project, click the project name, right-click and select the "Manage NuGet Packages" option.

    Enter firesharp, select FireSharp.Serialization.JsonNet (the second one), and download.

    Google search https://firebase.google.com/, click Get started >Add project, enter your customized database name, and click create.

    Click database under DEVELOP on the right side of firebase, select Realtime Database, click Get started> Start in test mode> Enable.

    Gets the link at the top of the white box of the current page as the value of BasePath.

    In the menu bar on the right, click Project settings>Service Accounts>Database Secrets to display the Secret of the current database as the value of AuthSecret.

    Here is the code to connect to the firebase:

    using FireSharp.Config;
    using FireSharp.Interfaces;
    using FireSharp.Response;
     
    IFirebaseConfig config = new FirebaseConfig
     {
        AuthSecret = "",//Value obtained from firebase above
        BasePath = "",//Value obtained from firebase above
     };
     IFirebaseClient client;
    private void Form1_Load(object sender, EventArgs e)
    {
    client = new FireSharp.FirebaseClient(config);
    if (client != null)
    {
    MessageBox.Show("connect is successful");
    }
    }

    You can use the following code to add, update, delete, and retrieve the data in firebase.

     internal class Data
        {
            public string Id { get; set; }
            public string Name { get; set; }
            public string Address { get; set; }
            public string Age { get; set; }
        }
     private async void button1_Click(object sender, EventArgs e)
            {
                var data = new Data
                {
                    Id = textBox1.Text,
                    Name = textBox2.Text,
                    Address = textBox3.Text,
                    Age = textBox4.Text,
                };
                SetResponse response = await client.SetTaskAsync("Information/" + textBox1.Text, data);
                Data result = response.ResultAs<Data>();
                MessageBox.Show("Data Inserted " + result.Id);
            }
    
            private async void button2_Click(object sender, EventArgs e)
            {
                FirebaseResponse response = await client.GetTaskAsync("Information/" + textBox1.Text);
                Data obj = response.ResultAs<Data>();
                textBox1.Text = obj.Id;
                textBox2.Text = obj.Name;
                textBox3.Text = obj.Address;
                textBox4.Text = obj.Age;
    
                MessageBox.Show("Data Retrieved successfully");
            }
    
            private async void button3_Click(object sender, EventArgs e)
            {
                var data = new Data
                {
                    Id = textBox1.Text,
                    Name = textBox2.Text,
                    Address = textBox3.Text,
                    Age = textBox4.Text,
                };
    
                FirebaseResponse response = await client.UpdateTaskAsync("Information/" + textBox1.Text, data);
                Data result = response.ResultAs<Data>();
                MessageBox.Show("Data updated at Id:" + result.Id);
    
            }
    
            private async void button4_Click(object sender, EventArgs e)
            {
                FirebaseResponse response = await client.DeleteTaskAsync("Information/" + textBox1.Text);
    
                MessageBox.Show("Delete at Id :" + textBox1.Text);
    
            }
    
            private async void button5_Click(object sender, EventArgs e)
            {
                FirebaseResponse response = await client.DeleteTaskAsync("Information");
    
                MessageBox.Show("All Data Delete /Information node has been deleted");
            }

    Here is the result of this work demo:

    For more details, I suggest you learn the following videos teaching, which will teach you how to use firebase for data operation in detail.

    How to connect to firebase : https://www.youtube.com/watch?v=jZMwwZHJXJc

    How to insert data to firebase : https://www.youtube.com/watch?v=_jB2iOgo_9Q&pbjreload=10

    How to retrive data from firebase : https://www.youtube.com/watch?v=Ryrkh0wSBTE

    How to update data in firebase : https://www.youtube.com/watch?v=DWyi7GH9Pgw

    How to delete data in firebase: youtube.com/watch?v=cbZTx3ykEVA

    Best Regards,

    YongQing.

    Tuesday, November 26, 2019 6:45 AM