Import system data and then oledb okay that will be and then let's also do this.
Import system diagnostic this will be so that we can print it and see our data there in the output and then uh later on we might also need to.
Read from csv so let's do this okay that will be it for now um let's set up a public uh variable which will hold our oledb connection.
Let's call this db on as a variable name and then ledb connection and then our pot shift right click copy a spot.
And let's call this i'll just paste this um so that will be our database parts now let's create a public function um.
So that we can reuse this connection uh from any of the sub procedures that we'll be reading uh let's call this open connection.
I think that should be it and this will return as pulling open connection okay now let's try to connect to database and um using tray.
Exception uh so here we'll say connection dot connection string school do for those of you who have watched the prior you know like other database sql ado you know like all these.
Series you must be already familiar with all this uh if not you can go and grab the connection string from this.
Website uh it has all the you know like drivers and uh connection string so it's very useful website for now i'm just gonna get this uh otherwise you can also.
- SharePoint Online Site Manager Beginner Tutorial
- Google Sheets Beginner Tutorial
- SSRS 2016 Part 1 - Creating and Deploying Your First Report
You know i will talk more at the later - ID Card Make
Stage how to connect you know if there's a password and all this okay um so i just copied this part and i'm gonna come back here our.Connection string will be this okay and of course the part will be okay so that's our parts um and then now we're gonna have.
Dbconnection.open now if this part fails then it's going to come down here uh if this part goes through then we want to return return true else if it goes down here.
That's where the error happened and then we want to return false okay and we can quickly test this out so just so we can say if this.
if connection is true then we'll say mrs box connected and if it is connected we want to disconnect this.
We'll close the connection else we'll say filter connect now let's add a quick ribbon to this uh project.
Let's add a ribbon designer uh let's call just call this ribbon one so we can add button to call this uh otherwise we can also directly add it.
To the worksheet um if you want to add a button here you can just go to the toolbar and then drag and drop the button okay for example like this.
Uh it takes time to repaint and you can double click here and then you can add the code yeah so i think for now let's go with this.
Fire this open debug mode
So it says fail to connect uh now it's a good time to debug close this and end it uh let's see what is wrong.Now what we can do is just disable this try catch for now and let's try and run this again just to see the error okay.
Or we can put a message box here without disabling it but okay so it says cannot use this file is already in use okay so the first time when we create a.
Database um it's you know like in exclusive of uh mode so we'll just close this okay and we can reopen it so that the mod is uh not in.
Exclusive mode allowing others to also connect the same database at the same time okay now let's go ahead and try again it's gonna bring back.
This is connected okay so uh we are now we have successfully set up our connection to the database in the next episode we will start uh running or commands and using more.
Other functions and methods so you.