Skip to content

Commit

Permalink
Extract database from connection string
Browse files Browse the repository at this point in the history
  • Loading branch information
taddison committed Dec 19, 2017
1 parent 97a9fe9 commit 9ef19a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ Spelunk your MSSQL code

# Usage
Command line usage requires three arguments:
- Connection string
- Connection string (must specify database/initial catalog)
- SQL script to parse
- Database name

```powershell
c:\source\SQLSpelunker\src\SQLSpelunker.Console>dotnet run "server=localhost;initial catalog=foo;integrated security=sspi" "exec dbo.SomeProc"; "foo"
c:\source\SQLSpelunker\src\SQLSpelunker.Console>dotnet run "server=localhost;initial catalog=foo;integrated security=sspi" "exec dbo.SomeProc"
```
8 changes: 5 additions & 3 deletions src/SQLSpelunker.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using SQLSpelunker.Core;
using System;
using System.Data.SqlClient;

namespace SQLSpelunker.Console
{
Expand All @@ -9,17 +10,18 @@ static void Main(string[] args)
{
var connectionString = "server=localhost;initial catalog=tsqlscheduler;integrated security=sspi";
var sqlScript = "exec scheduler.UpsertJobsForAllTasks";
var currentDatabase = "tsqlscheduler";

if(args.Length > 0)
{
connectionString = args[0];
sqlScript = args[1];
currentDatabase = args[2];
}

var builder = new SqlConnectionStringBuilder(connectionString);
var database = builder.InitialCatalog;

var sw = new ScriptWalker(new SQLDatabaseDefinitionService(connectionString));
var callChain = sw.GetCalledProcedures(sqlScript, currentDatabase);
var callChain = sw.GetCalledProcedures(sqlScript, database);
System.Console.WriteLine(callChain.GetCallHierarchy());
}
}
Expand Down

0 comments on commit 9ef19a2

Please sign in to comment.