Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use SqlConnection.GetSchema to get synonym information?

With code like this:

DataTable schema = conn.GetSchema();
DataTable tables = conn.GetSchema("Tables");
DataTable columns = conn.GetSchema("Columns");

Quite a lot of information can be fetched about the schema, but the metadata version (ie: GetSchema()) doesn't return anything about synonyms.

We use Synonyms quite heavily in our environment. Can I get Schema information about them using GetSchema, or do I need another method?

like image 616
The Evil Greebo Avatar asked Aug 10 '15 15:08

The Evil Greebo


1 Answers

There is not a schema collection for Synonyms for SQL Server:

SQL Server Schema Collections

There does appear to be a way to override the collections with .NET 3.5. I have never done this though so I don't know if it actually works. The basic idea is that you create an XML file to define how getschema defines and queries for schema data. You then change your applications configuration to use this XML file to override the collections that are available.

GetSchema Override

There are examples in the provided link to add a Primary Keys collection to the schema. It looks promising if your determined to use getschema. Otherwise you could create your own schema functions and just query sys.synonyms to get synonyms.

like image 139
Brian Pressler Avatar answered Oct 19 '22 08:10

Brian Pressler