StrataFrame Forum

How to discover network address of server from within app

http://forum.strataframe.net/Topic29413.aspx

By Charles R Hankey - 1/20/2011

Mind going blank -

what is the syntax to discover the network address of the box with the  sql server my app is connected to?

for some reason I'm drawing a blank on how to reference the application connection ... ??? 

I want to direct temp files for a process to the same box as the sql server ( I'm deserializing and manipulating stored pdfs ) to cut down on WAN traffic on a VPN.
By Trent L. Taylor - 1/21/2011

Well, this would depend on how you are trying to accomplish this.  You can get the machine name / IP address out of the connection string from the data source, but this won't give you the share of that machine.  If you just have a machine name, you can use the

Dns.Resolve("MachineName")


to get the IP of the machine.  But if you have the machine name that too may be enough.  The second part of this is knowing the share of the machine.  Before we move on, another way to parse a connection string is to place it in an SqlConnectionStringBuild and you get get the machine part:

System.Data.SqlClient.SqlConnectionStringBuilder sql = new SqlConnectionStringBuilder(MicroFour.StrataFrame.Data.DataBasics.DataSources[""].ConnectionString);


After you have the machine name, there are other obstacles before you can start writing files.  One thought may be to use the new FILESTREAM option in SQL Server 2008.  The DDT supports this now as well if you choose to go down this path.  This can be more complicated on deployment, but the files are stored externally from SQL but processed through SQL.  This way you can use Express and not eat into your database size while still going through your data process.
By Charles R Hankey - 1/21/2011

Thanks very much, Trent.  This should get me going.  I have control of the server box so I can precreate the server folders and their permissions.  Just wanted to learn the trick of discovering the server box's name so I didn't have to rely on making it an app setting ( If I did that I was considering pulling it when the connectionmanager first found the database after installation )

Good to know DDT is supporting Filestream as I'm also considering that for some other stuff.

And good luck with Rob Ryan Smile
By Edhy Rijo - 1/21/2011

Charles R Hankey (1/21/2011)
...I have control of the server box so I can precreate the server folders and their permissions.  Just wanted to learn the trick of discovering the server box's name so I didn't have to rely on making it an app setting ( If I did that I was considering pulling it when the connectionmanager first found the database after installation )

Hi Charles,
Even though you may have control of the network for this application, I would use this server location in a configuration table instead so you can simply choose the location and use it everywhere you need it in your application.

Relying on finding networking shares could be tricky and if for whatever reason in the future the network configuration changes (ex: Server crash, etc) then your application could end up broken.
By Ivan George Borges - 1/21/2011

Hi Charles.

Expanding a bit from what Trent gave you:

        '-- estabilish locals
        Dim connString As String
        Dim serverName As String
        Dim parseConnString As New Data.SqlClient.SqlConnectionStringBuilder

        '-- get the active connection string
        connString = ConnectionManager.GetApplicationActiveConnectionString("MyApplicationKey", "")
        '-- set the parser connection string
        parseConnString.ConnectionString = connString
        '-- get the server name from the parser
        serverName = parseConnString.DataSource
By Trent L. Taylor - 1/21/2011

And good luck with Rob Ryan


Yeah...you passed him off to us.  But if you look at the stats, he did improve your defense a lot.  If they keep Colt McCoy in as starter this next year, I think that you may finally have a quarterback!