Extracting the database’s name or path from the connection string

Extracting the database’s name or path from the connection string

' Return the Database name if the input connection string points to a SQL ' Server DB, or the DB path if the connection string points to a Jet (Access) DB' ' Examples:'   Debug.WriteLine(GetDatabaseName("Provider=Microsoft.Jet.OLEDB.4.0;Data ' Source=D:MyDB.mdb;")) ' => D:MyDB.mdb;'   Debug.WriteLine(GetDatabaseName("Provider=SQLOLEDB.1;Data Source=.;User ' ID=sa;Password=;Initial Catalog=MyDB")) ' => MyDB'   Debug.WriteLine(GetDatabaseName("server=(local);database=MyDB;uid=sa;pwd=;")' ) ' => MyDBFunction GetDatabaseName(ByVal connString As String) As String    Dim lcConnString = connString.ToLower()    ' if this is a Jet database, find the index of the "data source" setting    Dim startIndex As Integer    If lcConnString.IndexOf("jet.oledb") > -1 Then        startIndex = lcConnString.IndexOf("data source=")        If startIndex > -1 Then startIndex += 12    Else        ' if this is a SQL Server database, find the index of the "initial         ' catalog" or "database" setting        startIndex = lcConnString.IndexOf("initial catalog=")        If startIndex > -1 Then            startIndex += 16        Else ' if the "Initial Catalog" setting is not found,             '  try with "Database"            startIndex = lcConnString.IndexOf("database=")            If startIndex > -1 Then startIndex += 9        End If    End If    ' if the "database", "data source" or "initial catalog" values are not     ' found, return an empty string    If startIndex = -1 Then Return ""    ' find where the database name/path ends    Dim endIndex As Integer = lcConnString.IndexOf(";", startIndex)    If endIndex = -1 Then endIndex = lcConnString.Length    ' return the substring with the database name/path    Return connString.Substring(startIndex, endIndex - startIndex)End Function

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes