How to discover network address of server from within app


Author
Message
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
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.
Tags
Trent Taylor
Trent Taylor
StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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.
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
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
Edhy Rijo
E
StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
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.

Edhy Rijo

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
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

Trent Taylor
Trent Taylor
StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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!

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search