Figuring sql server version via code

Hi

Is it possible to check in .net;

1. If sql server 2008 express is installed on a machine?

2. The name of sql server 2008 express instance or instances?

3. If a particular sql server 2008 express instance contains a specific 
database?

Many Thanks

Regards


0
John
3/20/2010 9:48:26 PM
sqlserver.programming 1873 articles. 0 followers. Follow

3 Replies
723 Views

Similar Articles

[PageSpeed] 34

You can use several methods to enumerate SQL Server instances.  Here are a 
couple:

http://msdn.microsoft.com/en-us/library/a6t1z9x2.aspx
http://www.sqldbatips.com/showarticle.asp?ID=45

To determine whether a specific instance contains a certain database, you 
can connect to the instance's master database and query the sys.databases 
catalog view.

-- 
Thanks

Michael Coles
SQL Server MVP
Author, "Expert SQL Server 2008 Encryption" 
(http://www.apress.com/book/view/1430224649)
----------------

"John" <info@nospam.infovis.co.uk> wrote in message 
news:%23ZY3QcHyKHA.2552@TK2MSFTNGP04.phx.gbl...
> Hi
>
> Is it possible to check in .net;
>
> 1. If sql server 2008 express is installed on a machine?
>
> 2. The name of sql server 2008 express instance or instances?
>
> 3. If a particular sql server 2008 express instance contains a specific 
> database?
>
> Many Thanks
>
> Regards
>
> 

0
Michael
3/21/2010 12:45:45 AM
> 1. If sql server 2008 express is installed on a machine?> 2. The name of 
> sql server 2008 express instance or instances?

SELECT
    SERVERPROPERTY ('ProductVersion') ProductVersion
    , SERVERPROPERTY ('ProductLevel') ProductLevel
    , SERVERPROPERTY ('Edition') Edition
    , SERVERPROPERTY ('ServerName') ServerName
    , SERVERPROPERTY ('InstanceName') InstanceName

and

> 3. If a particular sql server 2008 express instance contains a specific 
> database?

SELECT QUOTENAME(sdb.name)
FROM master.dbo.sysdatabases sdb
WHERE status & 32 != 32
    AND status & 64 != 64
    AND status & 128 != 128
    AND status & 256 != 256
    AND status & 512 != 512
    AND status & 1024 != 1024
    AND status & 4096 != 4096
    AND status & 32768 !=32768

The where clause is to eleminate stuff like offline db's and whatnot.

-- 
Jay Konigsberg
SQL Server DBA in Sacramento, CA
http://www.linkedin.com/in/jaykonigsberg

Live in Sacramento, CA?
Join the Sacramento SQL Server User Group on LinkedIn
http://www.linkedin.com/groups?home=&gid=2825448&trk=anet_ug_hm&goback=%2Emyg



"John" <info@nospam.infovis.co.uk> wrote in message 
news:%23ZY3QcHyKHA.2552@TK2MSFTNGP04.phx.gbl...
> Hi
>
> Is it possible to check in .net;
>
> 1. If sql server 2008 express is installed on a machine?
>
> 2. The name of sql server 2008 express instance or instances?
>
> 3. If a particular sql server 2008 express instance contains a specific 
> database?
>
> Many Thanks
>
> Regards
>
> 


0
Jay
3/21/2010 12:49:58 AM

"John" <info@nospam.infovis.co.uk> wrote in message 
news:#ZY3QcHyKHA.2552@TK2MSFTNGP04.phx.gbl...
> Hi
>
> Is it possible to check in .net;
>
> 1. If sql server 2008 express is installed on a machine?
>
> 2. The name of sql server 2008 express instance or instances?
>
> 3. If a particular sql server 2008 express instance contains a specific 
> database?
>
> Many Thanks

You can do all of this with SMO (or DMO in COM based apps, SMO is a .NET 
replacement). Do a google search on SMO and you will see how to check SQL 
instances, versions, etc. It has a nice method to iterate through all 
instances of SQL on a box.

As for databases, you need to be able to connect with an account with 
permissions to ask the question. If not, your questions (statements) will 
fall on empty ears, so to speak. If you don't have permissions, you can try 
to query the database in question, and if you have those rights, you will 
either get an exception (does not exist) or an answer. That is a crude, last 
ditch effort, of course.

-- 
Peace and Grace,
Greg

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

************************************************
|    Think outside the box!                        |
************************************************ 

0
Gregory
3/22/2010 5:51:25 PM
Reply:

Similar Artilces:

currency in figures in words
Dears, would appreciate if any help on my below query I have currency in numbers which I need in words, e.g. if I enter in field A1 505 , once I come out of the field, in B1 I should get Five Hundred And Five Dollars thanks Gerald wrote: > Dears, > > would appreciate if any help on my below query > > I have currency in numbers which I need in words, e.g. if I enter in field > A1 505 , once I come out of the field, in B1 I should get Five Hundred And > Five Dollars > thanks Hi Gerald, This link to Microsoft might help you: http://support.microsoft.com/?kbid=21...

Not all versions of fonts installed showing up in Publisher...
I want to use Trebuchet Italics--not the style tool on plain Trebuchet, but it doesn't show up as a choice in Publisher. I checked and the Italics version is installed on my computer. How do I get it to show up in Publisher? Thanks! Lori On the Font Schemes task pane, click Styles and Formatting, select what formatting you want to change and click the italic look. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "lori" <lori@discussions.microsoft.com> wrote in message news:03A14085-D0F9-4FDC-AB23-BAA1DCE983E3@micr...

SQL AND GP8.0 in different servers.
Hi, How can I install GP 8.0 like Server if SQL Server is install in other server? Is that possible? I have two different servers for each one and I need to initialize GP, running GP utilities to create DYNAMICS database and COMPANY database... Thanks, -- Evelin. This can be done. I am not sure I understand the situation as Great Plains is the client communicating to the server. Usually Great Plains is installed on the SQL Server as well but it is not mandatory. To do what you want all you need to do is to set up an ODBC DSN on the one server that points to the other to apply the d...

Trouble with my Lookup Code
Hi Everyone. I’m adding a cost lookup to my db, based on the example in the Tradewinds database. I am trying to add a “CostPerFoot” value to the form automatically, based on the “MaterialType” entered by the user. Both of these fields are maintained in the “MaterialCostTable”. Here is what my ‘after update’ looks like on the “Material Type” field of the entry form: Private Sub MaterialType_AfterUpdate() On Error GoTo Err_MaterialType_AfterUpdate Dim strFilter As String ' Evaluate filter before it's passed to DLookup function. strFilter = "MaterialType =...

SQL logs
I'm working on a test environment, and I attempted to delete the log files, and now everything is a mess. When I try to access the CRM server I get this error: The Microsoft CRM server or security service has been disabled or has not yet started. For more information, contact your system administrator. and if I try to look at the database in SQL Ent. it shows nothing! any ideas? -Gary if you delete the transaction logs, do you lose all core data? -Gary "Gary" <gary.rey@virtium.NOSPAM.com> wrote in message news:%23Q0qGeMHEHA.712@tk2msftngp13.phx.gbl... > I'm w...

Keeping figures and cross references together.
Hi there, I'm creating a fairly long document with lots of figures (linked graphics). All graphics/figures will use a full page. On pages before the graphics/figures, I will use cross references to the following graphics/figures. Between the cross reference and the actual graphic/figure will be additional text. Is there a way to ensure that the very next page after the cross reference will always be the full page figure? In other words: when inserting additional text between the cross reference and the respective full page graphic/figure on the next page, can I ensure tha...

default setting on my 2002 version have just started happening
I pulled up publisher today and it is asking me to insert information onto previously saved documents and changing the look and function of each document....does anyone know how I could stop this or what is causing it. Would appreciate any help... Thank you!!!! What do you mean it's asking you to insert information from another document? Did you do some sort of merge on these documents? Specifically what is the message you are getting? -- JoAnn Paules MVP Microsoft [Publisher] "Help" <mstgsaly13@sbcglobal.net> wrote in message news:f4c501c43db9$107147c0$a001280a@p...

How to change SQL database location used in Excel 2000 pivot table
I have moved the relevant database from one SQL server to another, changed the relevant ODBC data source which now works for other applications but all of the pivot tables etc linked to the database through Excel cannot be redirected to the new database location. Final solution is to recreate them all from scratch. Not familiar with connections to sql, but can you not re-invoke the pivot table wizard and press the back button in the dialog that results, this should give you the option to re-establish the data -- HTH Nick Hodge Microsoft MVP - Excel Southampton, England nick_hodgeTAKET...

Help me understand this piece of MFC code
I have come across this piece of code in MFC CtrlBars Sample.... I am not able to follow what they are trying to do out of this code... Can somebody help me understand this code, // look for any top-level windows owned by us // we use 'HWND's to avoid generation of too many temporary CWnds for (HWND hWnd = ::GetWindow(m_pMainWnd->m_hWnd, GW_HWNDFIRST); hWnd != NULL; hWnd = ::GetNextWindow(hWnd, GW_HWNDNEXT)) { if (::GetParent(hWnd) == m_pMainWnd->m_hWnd) { // if owned window is active, move the activation to the application window if (GetActiveWindow() == hWnd && (::G...

Changing Opening Figures
Is it possible for us to change the opening figures inserted while installing the GP System. Basically we need to know whether the figures once added can be changed later or not. We need this information for opening figures taken on stocks in the system. Regards Eric ...

Six figures are in document but do not appear in List of Figures?
Created a document in Word 2007. Has amost 220 figures. Most appear in the List of Tables, but have troubleshot down to six that do not appear in Table. I have tried "update table" command, manually updated surrounding figures, deleted then added same figure back in. However, nothing works. List of Figures jumps from 105 to 107. While I can see Figure 106 in the base document. Any Suggestions? Make sure the missing figure captions in the body have been created using the same style name as those that do appear. Make all style names for figure captions consisten...

send mail between 2 exchange 2003 servers
Hi, i have 2 exchange 2003 server in a different domain. How can i send mail directly from the first to the other one ? via smtp connecter, it's not working because i get authentication errors in the logging. regards, Birgen "Birgen" <anonymous@discussions.microsoft.com> wrote in message news:2e04901c46c08$262d7cf0$a601280a@phx.gbl... > Hi, > > i have 2 exchange 2003 server in a different domain. > How can i send mail directly from the first to the other > one ? > via smtp connecter, it's not working because i get > authentication errors in ...

Upgrading IE Has Turned My Computer Into an XP Version of Vista
I have held off upgrading from version 6 of IE for as long as possible for exactly the kind of thing that happened, but a website I use routinely has forced me to upgrade. After upgrading I now get nag messages when I do various activities that have absolutely nothing to do with the browser. I get warning messages when I start programs and various ordinary activities. I get the following warning when I put a picture in Photoshop and even when I copy a file from one drive to another: http://img180.imageshack.us/img180/8206/0138.png jim In case it isn't obvious the questi...

save the information from an xml in sql
hi all. I need to save the mass information from an xml in sql database from c # is not how. thanks -- desarrollo On 01-03-2010 14:48, paulcc84 wrote: > hi all. I need to save the mass information from an xml in > sql database from c # is not how. thanks Do you want to parse the XML on the C# and insert normal database types or do you want to have SQLServer handle the XML? Arne want to parse the XML on the C# and insert normal database type -- desarrollo "Arne Vajhøj" wrote: > On 01-03-2010 14:48, paulcc84 wrote: > > hi all. I nee...

HELP!!!! Can't figure my problem out
hello... and thank you in advance to anyone that can assist me with my problem... I'm running Outlook 2000 on XP connecting to an internal Exchange 2000 server... When some of the workstations start up Outlook they get the following error "Your Microsoft Exchange Server is unavaliable You can retry connecting to the server using the network, or work off-line and connect using dial-up networking. The network did not respond in a timely fashion to determine the existance of an Exchange Server, you may retry and continue waiting for a responds or work off-line" If you se...

Closing Balance figure to be carried as Opening Balance in a new record 01-27-10
I have fields like Opening Balance and Closing Balance besides other fields. I want the closing balance of one record to be carried as opening balance for the next new record. Please help me urgently. It is a number field at both the places. -- Message posted via http://www.accessmonster.com Are you talking about entering one record then entering the next record, carrying the Closing Balance forward into the Opening Balance? Or are you talking about entering one record, closing the form, then coming back at a later date then and entering entering the next record, carrying th...

Concern with SQL database size
Hi, Since we are only allowed to disable users, business units, teams and etc from MSCRM database, what will happen to the SQL database size at the end of the day? Is there any house keeping meachanism to pervent database from oversize? Thanks for helping. Over time the database will continue to grow as a CRM solution will keep adding data daily. Over time I expect to see an archive feature but this may not appear for a few more versions. Becuase if this you should always specifiy way more data storage than you need for SQL. of course determining the amount of storage needed is an art in ...

SQL Query and connection help
I would like to have a excel sheet connect to a db and run a query that can be refreshed. Can someone give me an example on how to do this with vb in code view? I found many examples but either none work, or I can get the data to be displayed on the worksheet. Excel 2007 ...

DPM 2010 RC not Truncating SQL Logs
I have DPM 2010 RC setup backing up SQL Server 2005, as you have suggested, with Synchronization taking place every 45 minutes and the express full backup once a day. The problem is that the transaction logs are not being truncated. Any suggestions? This is a fresh load of DPM 2010 RC on Server 2008 R2 Standard x64. Not truncating or not shrinking? DPM truncates log files if the recovery model is set to "FULL". In this scenario it doesn't shrink them though. You need to create a maintenance task to perform this action (shrink). "jjakober" wrot...

Enter Transaction through SQL
Is there a documented way to fully enter a transaction through only SQL statements? I'm currently loading information from an online store into the Transactions on Hold table and then having an auto-it script pull up the order and run it through. It is 99% effective but sometimes messes up and has to be restarted. Also, though I originally had it running in a virtualized enviornment, it was extremely slow at times and now requires a standalone PC to run. It would be nice if I could just run all of the SQL statements that would full enter the transaction as if I had hit the tend...

Inbox stops receiving email until server reboot
Ok, bare with me here, I am not the server admin, I’m just keep having this problem. Once a month or so, my inbox suddenly stops receiving email. Our server admin reboots the exchange server (Running server 2003 enterprise) and it suddenly works ok again. My account is the only one that this ever happens to. I can still send mail while this problem goes on, just not receive. I have more than a dozen email addresses pointing to my account, but so do several other people and they do not encounter this problem. Also, the email address does get a lot of spam. Around 150 +/- every 12-16 ...

Figures lie and liars figure....
Here is an example of how figures can be misleading,. I am referring to the Portfolio Performance stats that are given for your investments compared to Dow Jones and S&P. What happens is, say you have $20,000 invested in mutual funds, and YTD your return is 15%. Your mutual fund declared a big capital gain/dividend, which you automatically reinvested. Yesterday your $20,000 drops to $19,000, dropping your annualized return of course. Today, it's back up to $20,000, but with a $1,000 reinvested at today's prices. So now you have the same money as 2 days ago, but your ret...

Passing a query parameter using code to feed a subform
Hello, Can someone please help with this issue I have in wanting to reuse a query that is the source for a subform that is used across my database by many main forms. The query is itself linked to a grouped query (Max of date) so it potentially has many records behind it. It basically retrieves the latest price of stock. I want to pass a parameter to this query (StockID) to a) speed up Access loading the form (because I believe that unless you have a MDE it "tests" your query on loading) and b) keep my queries to one per job. Should I pass the parameter to the final query (a selec...

Sql Server Version # from dfb file
Hi all, Q1: Is there a way to tell what version number a dbf file is? Q2: Where can I find a list of version #'s, ex, 621 = SQL 2005 Background: Using VS2005 and VS2010 with SQL Server 2005 Express. Somehow the DB on the production server got updgraded. It works fine on the server but the production boxs cannot open the db. Message says: (paraphrased) cannot open db ver 661, server is running 655. So the db file on the server is 661 and the production box is running 655. I added SQL 2008 R2 to the production box and can now open the db, but I want to have the a...

Routing to a server via IP in 2003
We are in the process of migrating from Exchange 5.5 to an Exchange 2003 system. In the 5.5 server, we were routing SMTP traffic for another group on our network to the fixed IP of thier smtp server. In 5.5, the configuration was in Internet Mail Connection properties, under the Connections tab, and you had to click on the Specify by Email Domain button and manually add the domain and the IP address. How would I approach it in 2003? Jackie On 11 May 2006 15:40:32 -0700, "JD" <jackie.dunning@gmail.com> wrote: >We are in the process of migrating from Exchange 5.5 to an ...