What is <user>#<server> notation called? - database

When connecting to a database or server, what is that particular kind of notation called?

Account name syntax is 'user_name'#'host_name'.
It’s called account name syntax, at least in MySQL documentation.

Related

Snowflake server name is different

I am trying to fetch server name on snowflake and it says
https://app.snowflake.com/europe-west4.gcp
When I try to connect to qliksense, the error is as follows -
"Connections are only allowed to *.snowflakecomputing.com hosts"
I believe I must've messed up the set-up somewhere but unable to figure out exactly what. This is a trial account I am exploring btw. I am newbie to snowflake and any help is appreciable. Thanks !
Finding the Region and Locator for an Account
If you can connect to your Snowflake account, you can query the following context functions to identify the region and account locator for the Snowflake account you are connected to:
CURRENT_REGION retrieves the region in which your account is located.
CURRENT_ACCOUNT retrieves the account locator.
Account URL could also be copied using Snowsight UI:

Testing Connection Parameters with NHibernate

We have a program where users can specify their database connection parameters. The usual suspects including host, port, username, password, and table name. We are connecting to the database using NHibernate. What we'd like to do is be able to build the configuration with NHibernate and then test the connection parameters before continuing with other operations; notifying the user of failure.
Is this possible to do through NHibernate, or will it require using each database type we support's specific driver and creating a custom TestConnection() method for each type?
I realize this is an old post - but I guess an answer to a question never hurts.
I don't think there is a way to explicitly tell NHibernate to test out the connection string. However, when you instantiate the SessionFactory it will attempt to connect to the database. You could wrap your SessionFactory creation in a Try/Catch and handle the error that way.
I use Fluent NHibernate, but I'm sure the following example will still explain the situation.
Dim sf as SessionFactory
Try
sf = CreateSessionFactory()
Catch ex as FluentNHibernate.Cfg.FluentConfigurationException
Messagebox.Show(ex.InnerException.Message)
End Try
The ex.InnerException.Message contains the actual error and will tell you if:
The connection string was invalid
The server could not be found
The user/pass could not be authenticated
To configure Nhibernate you have two options:
Set the dialect when you are building the session factory. This will assign reasonable default value to Nhibernate's ADO and other configuration values.
Manually set the configuration values.
That said, at some point, you need to configure Nhibernate to use the appropriate driver for the database you want to talk to. Which means you need to be able to build Session Factories of different types (your supported database types). To do this you need more than just "host, port, username, password, and table name". You need to know the database type(Dialect).
If you intend to just try to connect the database with every driver available to you not knowing what the database type is, you may run into problems when the database and the dialect don't match. Imagine you use a SqlServer2008 dialect on SqlServer2005 machine. The difference in dialect can cause a particular SqlServer2008 feature you are using not to, obviously, work. Moreover, if you don't stick to basic SQL through out all your code, you may be generating Sql that works, say, in PostgreSql but not in SqlServer (Think sequences and such).
To learn more about configuring Nhibernate read:
Chapter 3: Session Factory Configuration. Specially sections 3.3, 3.4, 3.5 which talk about configuration parameters.
Last note, Nhibernate supports multiple databases. But, for complex domain layers where you rely on database specific constructs, your code doesn't.

Connect to the same database, but as a another user, without hardcoding a connection string

Can I use OPENDATASOURCE (or another mechanism) from a Stored Procedure to connect to the same database as a different user? If so, how?
The database is meant to be deployed to several customers, and replicated by them as many times as they want to, etc. For this reason, I CANNOT HARDCODE the database server's name or the database's name.
(I tried using OPENDATASOURCE, but it only accepts hardcoded connection strings.)
Might EXECUTE AS work in your situation? http://msdn.microsoft.com/en-us/library/ms181362.aspx
You can set up a Linked Server to connect to the remote server using the login's current security context (or other options as it applies to your situation).
From your stored procedure, you could access it with something like SELECT * FROM mylinkedservername.mylinkedserverdatabase.dbo.mytable
But you say you want to connect to the same database but using a different login? You're looking for impersonation. Perhaps you can do this making a Linked Server that references itself, I haven't tried it. Search Microsoft Help documentation for how to set it up normally and test if it does what you're looking to do.

Getting the local instance of SQL Server rather than a named instance

A while ago, I wrote a web-based guestbook application that wrote it's own database.
My code was very amateurish, but, as it was my very first publication, I was very happy with it.
Only about a month after I'd published it did I realize I'd made a huge mistake in the code.
I've only ever connected to a specific named instance of SQL Server, and it occurred to me that, if the SQL Server instance has a different name than the one I specified, it wouldn't work.
So, since my users will probably not know what the name of the instance of SQL Server that's running is, I thought adding a field where the user can specify it would help if they do, but what if they don't?
My answer was to get the local instance, regardless of name.
I tried Data Source=.\local;, Data Source=.; and other variants, but nothing worked.
Any ideas?
A non-named instance is called "default instance" and can be accessed using "Data Source=(local);...".
The only way of knowing which instances are running is by querying the SQL Browser Service, if it's running.
I guess most of your users are running SQL Server Express? If so, the service is called local\SQLEXPRESS. If not, it's local or they've named it themselves. So, I would try local\SQLEXPRESS first, then local. If none works, just throw an exception and ask the user to add it themselves.

How to change word-break characters in SQL Server Full-Text indexing

By default, when one tells SQL Server (currently using 2008) to Full-Text index a column, it treats characters such as "#" and "." as work-breakers, similarly to " ".
I'd like to restrict the work-breaking characters to just be " ", so that "joe.bloggs#somewhere.com" is treated as a single word.
It appears that one can choose a "Language for Word Breaker" against the indexed column - perhaps I need to set up a custom language?
Does anyone know how I can do this?
In order to make your word breaker fly with SQL Server you have to disable signature verification and add your COM CLSID to the registry. For more info check out this post: http://blogs.msdn.com/shajan/default.aspx
It helped me a lot! However I never managed to create my own language so I simply hijacked an already existing one.
According to TechNet's article on SQL 2008 Full-Text Search:
well-known published interfaces
provide the framework for Full-Text
Engine extensibility. For more
information, see the Microsoft
Developer Network (MSDN) topics
IFilter, IWordBreaker, and IStemmer.
So, at least according to this article, you can implement a custom IWordBreaker implementation (see http://www.siao2.com/2005/03/14/395199.aspx for more info) and get SQL to use it.
What I haven't found so far is how to plug your custom word-breaker into SQL itself-- how to tell SQL to use your word-breaker. Sorry for the incomplete answer... hope I got you at least part of the way to a solution.

Resources