Check for the server name in connection string if it exists or not - vb.net

I have done a program where in which I'll pass the server name to the connection string at run time. I need to check if the server name is valid.
Help me out with this?

Try using the SqlDataSourceEnumerator.Instance.GetDataSources() method to get a list of available SQL servers. (see MSDN: http://msdn.microsoft.com/en-us/library/system.data.sql.sqldatasourceenumerator.getdatasources.aspx)
You alternatively might want to connect to the server in a Try..Catch block and check if the connection status is 'open'.

Related

Redis How to get current database name

Is there any command in Redis to get the database name that I am using right now?
I know select is to switch the database. I am looking for "get database name" kind of a command.
First of all, there's NO name for Redis database. Instead, it has an index.
You can use the CLIENT SETNAME and CLIENT LIST commands to get the database index dynamically:
call CLIENT SETNAME a-unique-name to set a unique name for the current connection.
call CLIENT LIST to get info of all clients that connecting to Redis.
find the connection info with the unique name that we set in step 1.
parse the client info the get the database index.
You can get the format of client info from the doc.
NOTE: If anyone has a simpler solution, please let me know :)
UPDATE: Since Redis 6.2.0, you can use CLIENT INFO to get the information of current connection. So that you don't need to run step 1 - 3 mentioned above.
Since Redis version 6.2.0 you can use the CLIENT INFO command, the response of which contains both the name and the db number of the current client connection.

how to use sql server packages in go

I use the denisenkom/go-mssqldb package for connecting to SQL server in go but I don't know how to write the connecting code,
what are the arguments of this method : sql.Open() for example when we say :
db, err := sql.Open("mysql", "user:password#/database")
what do "mysql" and "user:password#/database" refer to?
and in which part of the program we should tell the name of the database which we want to use in the program? I mean in which part of the code we introduce the name of the database we want to use?
"mssql" is the protocol/driver/database type you are connecting to. "user:password#/database" is the connection string. See this example for the components of this String.
Your application typically knows the database it wants to connect. Or at last when the user logs in.

Postgresql job scheduler using pgagent giving error with update query

I have created a job scheduler using pgagent in postgresql:
What I did is mentioned as screen shots
I had created like this to update name in my database field in a certain time. But when I check it is getting failed.
The failed status as follows:
What I did wrong? How can I correct it?
I have also faced the same problem exactly. By trial and error, I changed the Connection Type from Local to Remote and gave the following connection string
user=some_user password=some_password host=localhost port=5432 dbname=some_database
in the properties of the Step. And, it worked. So, the trick is to treat even the local server as a remote server.

Get instance name from data source name

I'm using SQLDriverConnect function to connect to database. In connection string I can specify ODBC pre-configured data source name (DSN), function resolves necessary attributes and all works fine. But after successful connection I need to get instance name to which I have connected or connection port (because there can be several instances of mssql running on server). How can I implement this?
Run the following query on your connection:
select ##SERVERNAME
This will return the server and instance name
The preferred form is apparently to use SERVERPROPERY:
SELECT SERVERPROPERTY('ServerName')
which will return the server and instance name, and, unlike ##SERVERNAME, correctly returns results if the server has been renamed.

Accessing 'Global' Variables In An ExecuteSQL Task

I have an SSIS package that does the following:
Selects the connection strings from a table of servers. The connection string is either the name of the server along with the domain (i.e. Dalin.myhouse.com) or is the direct IP to a server.
The package iterates through each connection string and populates a defined 'global' variable. This variable was created with in the Variable designer. For each connection string, the package will retrieve information about the server.
The problem I'm having is when you add a server IP to the list, the 'Friendly Name' may not be known at that time so I would just have the server IP in both the connection string column and the friendly name column of the table. I want to, after the end of an iteration, update that the Friendly Name column of the server entry within that table so that it has the server name pulled from the server using SERVERPROPERTY('Servername')
To do this, I would like to use an ExecuteSQL Task with the following code:
UPDATE [myDB].[mySchema].[myServers]
SET [ServerName] = VarA
WHERE ConnectionString = VarB
The previous code is using a static connection to the server where the myServers table resides.
VarA represents the global value I want to set the ServerName to which would be set in a separate SQLTask by using SERVERPROPERTY('Servername'). It needs to be in a separate task because it would have to connect to a server by using the same server the current iteration is using.
VarB is set at the beginning of every iteration to the next Connection String in the list.
I've seen examples on how to use this for the Script Task and Script Components but I would like to simply use the ExecuteSQL Task to accomplish this.
Summary:
Connect to ServerA and fill two global variables.
Connect to ServerB and use the two global variables to update a specific row in a table.
Any ideas?
I can't see how this can be accomplished without the variables being set within a Script Task, since ExecuteSQL tasks have to be set to a database connection. Script Tasks work for this because their connection is within the context of the server that's executing them. That being said, you could use a Script Task prior to this ExecuteSQL task that sets the variables to the local server instance.
So you need the Execute SQL task to take parameters?
http://msdn.microsoft.com/en-us/library/ms187685.aspx
Maybe I've misunderstood...