Rename a sql server instance - sql-server

Is it possible to change a sql server instance name? Or is it something that can only be set during installation?

To the best of my knowledge, they can only be changed at install time. You might be able to change the name with the installer package while keeping the current info. I would make backups of all of your databases and then try this.
On another note, changing instance names will just cause you so many headaches. Even if you can do it, I would strongly reccomend leaving well enough alone.

You can't rename the instance but you can rename a server (sql2000 only) - does that help at all?
Have a look at:
sp_dropserver 'oldname', 'droplogins'
and then;
sp_addserver 'newname', local
Be aware that if there are any jobs running on that server they'll need to be renamed too;
use msdb
go
update sysjobs set originating_server = 'newname'
You'll need to restart your SQL Server

Related

Can I manage database using database project without knowing connection string?

I have created database project. I am able to upgrade my changes in my sql server. Now I have deploy the same changes on another environment. Also I dont want to change my previous data. I dont have to access that Sql server so I don`t know the connection string.
I have some options, like to deploy the .dacpac file or .sql script, but it first delete the database then creates new one. So that I loosing my data.
Please help me. If any option is there?
The options I see for this are:
Ask for a backup (or extract schema tables using task-->Generate scripts ion ssms) - restore this somewhere and use sqlpackage to generate a deployment script you can ask them to run
Ask them to run sqlpackage.exe and either generate a script or run it directly
Ask them for permissions so you can do it
If the database is being deleted then you have the option "CreateNewDatabase" set to true which would be bad in a production environment so remove it or set it to false!
If they run it or you ask for permissions, these are the minimum permissions you need to generate a script (to run the script you will probably need dbo):
https://the.agilesql.club/Blogs/Ed-Elliott/What-Permissions-Do-I-Need-To-Generate-A-Deploy-Script-With-SSDT (my blog)

SQL Server Copy Database Issue

I'm running the copy database wizard on a 2008 R2 instance of SQL Server.
The database I want to copy is a SQL 2000 database.
I'm copy that database to another SQL SErver 2008 R2.
The wizard uses SQL authentication for both servers, and both are sysadmins.
When I run it, I get the following error (FYI I have tried both copying the logins and leaving them out):
Event Name: OnError
Message: ERROR : errorCode=-1073548784 description=Executing the query "sys.sp_addrolemember #rolename = N'RandomRoleName..." failed with the following error: "The role 'RandomRoleName' does not exist in the current database.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
helpFile= helpContext=0 idofInterfaceWithError={C81DFC5A-3B22-4DA3-BD3B-10BF861A7F9C}
StackTrace: at Microsoft.SqlServer.Management.Dts.DtsTransferProvider.ExecuteTransfer()
at Microsoft.SqlServer.Management.Smo.Transfer.TransferData()
at Microsoft.SqlServer.Dts.Tasks.TransferObjectsTask.TransferObjectsTask.TransferDatabasesUsingSMOTransfer()
Any help would be appreciated!
Jim
My suggestion is dont use the copy database wizard. Create a full backup of the database on the 2000 server and then restore it on the 2008 server.
If you google "Microsoft.SqlServer.Management.Dts.DtsTransferProvider.ExecuteTransfer Copy Database Wizard" you will find that many many people have gotten this same error or other nearly identical smo errors... no-one appears to have gotten past it.
That's isn't to say its impossible... just, restoring a backup is so much easier then the wizard or troubleshooting the wizard. Good luck.
The copy wizard had missed some security and IIRC it's caused by subtle differences in security tables, principals etc between the 2 versions.
Frankly, the easiest way is to do one of these two:
backup/restore
detach, copy, attach
If you don't have access to the O/S and can't get it, another option is to create the missing role(s) in the background as the copy runs. You have to catch it between the creation of the files and when it tries to reference the roles, but there are a few seconds in which to create them if you keep clicking execute - I managed to create 9 roles.
Unfortunately, you'll end up with the roles in another database too (while yours cannot be used) so those need to be deleted.
Of course, this is only an option when you really can't use the other method.
Though the answer which is using the backup technique solves the problem generally, after facing the same issue several times, I was able to trace down the root of the problem using the Event Viewer of Windows to that the Database Copy wizard, using the SQL Agent, will eventually create a Job for the agent to run, after which the Agent will run using its own credentials (i.e. the credentials that you can look up in Windows Services, in my case, NT Service\SQLAgent$SQL2014)
All you need to do is to go the folder where SQL Server creates DB files (e.g. C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\DATA by default for SQL 2014) and give the SQL Agent windows user write/read access on the folder.
The reason can be that a file with the new Database name already exist on the filesystem. We encountered this when we renamed Database X to X_Old, and tried to copy database Y to X. This cannot be done, because database X_Old is still associated with the filename X.
Either delete the conflicting database, or rename the file on the file system.
See http://codecopy.wordpress.com/2012/01/03/error-while-copying-a-database/

Force ##Servername to return something else in SQL Server

DISCLAIMER: While I'm trying to do this to fool a license enforcement scheme, the company is out of business and I'm only setting up a test server. I don't consider this stealing (as a developer that sells software myself, I wouldn't do that) since I can't pay for another license if I wanted to. However, if the community disagrees, please vote to close this question. Just want to be upfront about this.
We use a server app that, as part of its license enforcement, confirms that "SELECT ##SERVERNAME" matches the license installed on the server. I'm setting up a test instance of this application, but since the license I have is locked to a particular servername, I'm stuck.
Is there a way that I can fool ##SERVERNAME into returning something else? Change the internal name of the server to something different than the DNS name? I know there are SQL Server problems if you rename a server, and maybe I can exploit this to accomplish what I need to (rename the server to the licensed name, install SQL, then rename the server so it doesn't conflict with our production server).
If there is another, non-hacky way to accomplish this (set up an isolated domain, use a virtual server with no network connection, etc), I'd entertain those options as well. What does the community think is the easiest way to get this done?
It actually looks possible to set the server name property.
SQL 2000: http://msdn.microsoft.com/en-us/library/aa933172(SQL.80).aspx
SQL 2005: http://msdn.microsoft.com/en-us/library/ms174411(SQL.90).aspx
SQL 2008: http://msdn.microsoft.com/en-us/library/ms187944.aspx
I'd probably set up a separate machine or a virtual machine named after what the license manager was expecting. A bit tedious to set up, but it would probably get the job done quicker than looking for hacky solutions. Of course, while the install was running I'd still be looking just in case...
You might try using the sp_addserver stored proc on your test server to tell SQL Server that the server name is the one the license is looking for.
From the MS docs,
SQL Server Setup sets the server
name to the computer name during
installation. To change the name of
the server, use sp_addserver, and then
restart SQL Server.
Drop the 'local' linked server, then add it back with the name you want. sp_addserver 'foobar', 'local' will make ##server to return 'foobar'. See kb 303774

How to edit the SQL Agent Job from within SSMS 2005?

I am trying to edit or view the SQL Agent's job (I am the owner of this job) from SSMS 2005 and I can't find out how to do this. When I am double-clicking a job or entering job's properties I get empty "New Job" window.
Is there some way to correct this behavior?
You can genereate SQL Script for SQL Job and then edit it. right click the job and then
click generate SQL Script. Here you can also change the job properties with the sql sciript
I ran into this problem a while back. I'm not entirely sure what caused it, but the fix was installing sp2 of sql server onto my local machine (or whichever machine you're using ssms on). the only documentation i found at the time suggested that that was the only solution.
I suggest you create a new job explicitly, then try editing your new job the same way and see what happens.
In particular, it's possible that your old job really is empty.
not sure what your issue with SSMS is. Maybe you dont have permission?
Unless your sa you need to be a member of the SQLAgentOperatorRole in MSDB?
If you can still run queries then look at the sysjobs and sysjobsteps tables in the MSDB database, this has all the properties
You can use the sp_update_job to modify the job

Is it possible to rename an SQL Server 2005 instance

I would like to change the name of my SQL Server instance. Is there a simple way of doing this or is a significant effort required? Note, this is a named instance - not the default instance.
The only way is a reinstall. See this similar thread for more info: SQL Server, convert a named instance to default instance?
Or you could try this method:
http://groups.google.com/group/microsoft.public.sqlserver.server/browse_thread/thread/544c4eaf43ddfaf3/f1bdcd1ec9cab158#f1bdcd1ec9cab158
I have seen a few makeshift ways of doing this, but I don't have confidence in any of them. I think I will simply install a new instance and transfer my information over.
Renaming does't work well on the registry. Install a new isntance.
Although there is no simple way of renaming a SQL Server instance, one can create SQL aliases.

Resources