SSMS 2008 not remembering connection login credentials [duplicate] - passwords

I've recently used our company's spare laptop (that has a general user set up) while mine was being repaired. I've checked the "Remember password" option in SQL Server Management Studio when logging in to the database.
I need to clear the login and password information that I have used to prevent the next person that will use the laptop from using my login names and passwords. How can I do this?

Another answer here also mentions since 2012 you can remove Remove cached login via How to remove cached server names from the Connect to Server dialog?. Just confirmed this delete in MRU list works fine in 2016 and 2017.
SQL Server Management Studio 2017 delete the file
C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\14.0\SqlStudio.bin
SQL Server Management Studio 2016 delete the file
C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\13.0\SqlStudio.bin
SQL Server Management Studio 2014 delete the file
C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\12.0\SqlStudio.bin
SQL Server Management Studio 2012 delete the file
C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\11.0\SqlStudio.bin
SQL Server Management Studio 2008 delete the file C:\Users\%username%\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin
SQL Server Management Studio 2005 delete the file – same as above answer but the Vista path.
C:\Users\%username%\AppData\Roaming\Microsoft\Microsoft SQL Server\90\Tools\Shell\mru.dat
These are profile paths for Vista / 7 / 8.
EDIT:
Note, AppData is a hidden folder. You need to show hidden folders in explorer.
EDIT:
You can simply press delete from the Server / User name drop down (confirmed to be working for SSMS v18.0). Original source from https://blog.sqlauthority.com/2013/04/17/sql-server-remove-cached-login-from-ssms-connect-dialog-sql-in-sixty-seconds-049/ which mentioned that this feature is available since 2012!

This works for SQL Server Management Studio v18.0
The file "SqlStudio.bin" doesn't seem to exist any longer. Instead my settings are all stored in this file:
C:\Users\*********\AppData\Roaming\Microsoft\SQL Server Management Studio\18.0\UserSettings.xml
Open it in any Texteditor like Notepad++
ctrl+f for the username to be removed
then delete the entire <Element>.......</Element> block
that surrounds it.
EDIT:
An even easier and working solution for v18.0 (Preview 7) would be:
Go to the "Connect to Server" dialogue window:
Click the down-arrow icon marked green in the screenshot.
Use the arrow-keys on the keyboard to navigate up/down
Press the DEL key on keyboard to delete the entry.
Close the dialogue window and when you reopen it the entry will indeed be removed.

For those looking for the SSMS 2012 solution... see this answer:
Remove cached login 2012
Essentially, in 2012 you can delete the server from the server list dropdown which clears all cached logins for that server.
Works also in v17 (build 14.x).

In my scenario I only wanted to remove a specific username/password from the list which had many other saved connections I didn't want to forget. It turns out the SqlStudio.bin file others are discussing here is a .NET binary serialization of the Microsoft.SqlServer.Management.UserSettings.SqlStudio class, which can be deserialized, modified and reserialized to modify specific settings.
To accomplish removal of the specific login, I created a new C# .Net 4.6.1 console application and added a reference to the namespace which is located in the following dll: C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio\Microsoft.SqlServer.Management.UserSettings.dll (your path may differ slightly depending on SSMS version)
From there I could easily create and modify the settings as desired:
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Microsoft.SqlServer.Management.UserSettings;
class Program
{
static void Main(string[] args)
{
var settingsFile = new FileInfo(#"C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\13.0\SqlStudio.bin");
// Backup our original file just in case...
File.Copy(settingsFile.FullName, settingsFile.FullName + ".backup");
BinaryFormatter fmt = new BinaryFormatter();
SqlStudio settings = null;
using(var fs = settingsFile.Open(FileMode.Open))
{
settings = (SqlStudio)fmt.Deserialize(fs);
}
// The structure of server types / servers / connections requires us to loop
// through multiple nested collections to find the connection to be removed.
// We start here with the server types
var serverTypes = settings.SSMS.ConnectionOptions.ServerTypes;
foreach (var serverType in serverTypes)
{
foreach (var server in serverType.Value.Servers)
{
// Will store the connection for the provided server which should be removed
ServerConnectionSettings removeConn = null;
foreach (var conn in server.Connections)
{
if (conn.UserName == "adminUserThatShouldBeRemoved")
{
removeConn = conn;
break;
}
}
if (removeConn != null)
{
server.Connections.RemoveItem(removeConn);
}
}
}
using (var fs = settingsFile.Open(FileMode.Create))
{
fmt.Serialize(fs, settings);
}
}
}

There is a really simple way to do this using a more recent version of SQL Server Management Studio (I'm using 18.4)
Open the "Connect to Server" dialog
Click the "Server Name" dropdown so it opens
Press the down arrow on your keyboard to highlight a server name
Press delete on your keyboard
Login gone! No messing around with dlls or bin files.

Delete entire node "Element" (inside "Connections" tree) from XML file, used by version 18 or higher.
C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\18.0\UserSettings.xml

As gluecks pointed out, no more SqlStudio.bin in Microsoft SQL Server Management Studio 18. I also found this UserSettings.xml in C:\Users\userName\AppData\Roaming\Microsoft\SQL Server Management Studio\18.0. But removing the <Element> containing the credential seems not working, it comes right back on the xml file, if I close and re-open it again.
Turns out, you need to close the SQL Server Management Studio first, then edit the UserSettings.xml file in your favorite editor, e.g. Visual Studio Code. I guess it's cached somewhere in SSMS besides this xml file?! And it's not on Control Panel\All Control Panel Items\Credential Manager\Windows Credentials.

For SQL Server Management Studio 2008
You need to go C:\Documents and Settings\%username%\Application
Data\Microsoft\Microsoft SQL Server\100\Tools\Shell
Delete SqlStudio.bin

Delete:
C:\Documents and Settings\%Your Username%\Application Data\Microsoft\Microsoft SQL Server\90\Tools\Shell\mru.dat"

In XP, the .mru.dat file is in C:\Documents and Settings\Name\Application Data\Microsoft\Microsoft SQL Server\90\Tools\ShellSEM
However, removing it won't do anything.
To remove the list in XP, cut the sqlstudio bin file from C:\Documents and Settings\Name\Application Data\Microsoft\Microsoft SQL Server\100\Tools\Shell and paste it on your desktop.
Try SQL
If it has worked, then delete the sqlstudio bin file from desktop.
Easy :)

Select the Login drop down arrow. Delete the users from the list

Related

Lucee <cfadmin> does not correctly store connectionString property when executing an "updateDatasource" operation

I'm hoping someone can shed some light on this issue. I'm attempting to programmatically add datasources to the Lucee Server context (ie. not on a per-application basis, but rather datasources that are made available to all web contexts on the server). The following call to the tag to create the datasource or later update the same datasource results in the connectionString never being saved correctly.
NOTE: "updateDatasource" will create a datasource if it doesn't already exist.
Host Environment: Windows Server 2019 running Lucee 5.3.8.206 on OpenJDK17.
Database Environment: Windows Server 2019 running SQL Server 2019.
<cfadmin
action="updateDatasource"
type="server"
password="F4K31234"
bundlename="org.lucee.mssql"
bundleversion="8.4.1.jre8"
classname="com.microsoft.sqlserver.jdbc.SQLServerDriver"
dsn="my_new_datasource"
name="my_new_datasource"
newName="my_new_datasource"
connectionString="jdbc:sqlserver://SQLSERVERNAME\MSSQLSERVER2019;DATABASENAME=my_database;sendStringParametersAsUnicode=true;SelectMethod=direct"
dbusername="Temp1234"
dbpassword="F4K31234"
connectionLimit="100"
alwaysSetTimeout="true"
validate="false"
allowed_select="true"
allowed_insert="true"
allowed_update="true"
allowed_delete="true"
allowed_create="true"
allowed_revoke="true"
allowed_alter="true"
allowed_grant="true"
clob="true"
lineTimeout="60">
Every time this operation is attempted, the Connection String is stored as "my_database". In other words, it appears to ignore the string provided in the connectionString attribute and instead stores the database name for the datasource connection string.
These settings are exactly what I use when manually setting up a datasource in the Lucee Server administrative area (minus the obvious fake username, passwords, server names, and database names).
Before I go about filing a bug, I wanted to be sure I'm not missing something here. I appreciate any insight!

SQL - Another "SELECT Permission was denied on the object" Issue

(I know SO has well over a dozen questions with the same/similar title and I promise I've already gone through every one of them to no avail. I might have missed one or two minor details but I suspect my problem could be something more deep rooted. Enough said for intro)
Anyway, I have a database (let's call it FooDB) that I restored from a backup database. I can do whatever I want with it using SQL Server 2012 Management Studio, including SELECT, INSERT, or DELETE on any of the record, columns, or tables.
What I'm having trouble with is when I try to run a simple query against the same database, I get the following error:
An error has occurred.","ExceptionMessage":"The SELECT permission was denied on the object 'BarTable', database 'FooDB', schema 'dbo'."
There's a lot more to the stack trace but I won't post it here unless necessary. I'm using Visual Studio 2012 Ultimate and in one of the class files I specified the connection string as follows:
using (SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;" +
"Initial Catalog=FooDB;" +
"Integrated Security=true;"))
{
con.Open();
using (SqlCommand command = new SqlCommand("SELECT TOP 3 * FROM BarTable", con))
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
... // code in this block is not shown as it is irrelevant to the issue
}
}
}
Heeding to various suggestions I came across on SO, I tried the following:
In SQL Server Management Studio, I selected 'Security' -> 'Logins' -> Right-click on the Windows login name and open the 'Properties' dialog -> In 'Server Roles' page, I selected dbcreator, public, serveradmin, setupadmin, and sysadmin
While on the same 'Properties' dialog from above, I selected 'User Mapping' page, then checked the 'Map' checkbox for the database (FooDB), and assigned the following database role membership: db_accessadmin, db_backupoperator, db_datareader, db_datawriter, db_ddladmin, db_owner, db_securityadmin, and public
From the Object Explorer of the Server Management Studio, I selected 'Databases' -> 'FooDB' -> 'Security' -> 'Users' -> Then I right-clicked the Windows login name and selected 'Properties' to open the 'Database User' dialog. Then I selected 'Owned Schemas' page and checked db_backupoperator, db_datareader, and db_datawriter
While on the same dialog from above, I selected 'Membership' page, and checked db_accessadmin, db_backupoperator, db_datareader, db_datawriter, db_ddladmin, db_owner, and db_securityadmin
That's all I can think of at this moment. Again, from within the SQL Server Management Studio (after logging in with the same Windows Authentication and server name) I can do whatever I want to with the database. But from within my C# class, it seems I can connect to the database but I lack the privilege to perform any action.
This is something I've been wrestling with unsuccessfully for almost a week. What gives?
Is the server authentication set to SQL server and Windows Authentication mode?
To do so, right click on the SQLServer -> properties -> security.
Edit: Dint mean database, did mean the SqlServer
Have you tried running sp_change_users_login .
Sometimes when you restore a DB it creates new sid (security ids) for the users. When it does that, the DB user and the Server login look the same, but internally the sids don't match. sp_change_users_login will fix that.
Details on how to use the stored procedure can be found here:
https://msdn.microsoft.com/en-us/library/ms174378.aspx
Try this initially - you will have to edit it slightly to fit your user and login name:
EXEC sp_change_users_login 'update_one', 'YourDBUserName', 'YourServerLoginName';

How to open the .db paradox file

i want to view the test.db file, i search for it's editor but didn't get any one
So please help to see the it in editor as like sql server.
i found some sqlite editor but it's not an sqlite file on most forum it say that it is an paradox .db file.
So how do i open it
Thanks
To access Paradox tables in .NET you can use ODBC. Here's a small example (in C#):
private static void RunMinimumParadoxTest()
{
const string ConnectionStringFormat =
"Driver={{Microsoft Paradox Driver (*.db )}};Uid={0};UserCommitSync=Yes;Threads=3;SafeTransactions=0;" +
"ParadoxUserName={0};ParadoxNetStyle=4.x;ParadoxNetPath={1};PageTimeout=5;MaxScanRows=8;" +
"MaxBufferSize=65535;DriverID=538;Fil=Paradox 7.X;DefaultDir={2};Dbq={2};CollatingSequence={3}";
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.Odbc");
using (DbConnection connection = factory.CreateConnection())
{
string userName = "Tor";
string paradoxNetPath = #"C:\BdeNet";
string databasePath = #"C:\LangloMainSrv\LData\Ordre\LordWin\Database2011";
string collatingSequence = "Norwegian-Danish";
connection.ConnectionString =
String.Format(ConnectionStringFormat, userName, paradoxNetPath, databasePath, collatingSequence);
connection.Open();
using (DbCommand command = connection.CreateCommand())
{
command.CommandText = "select Count(*) from [OrdreDet] where [Ordrenr] = 81699002";
object itemCount = command.ExecuteScalar();
Console.WriteLine("Order items: {0}", itemCount);
Console.ReadKey();
}
}
}
Also see the following link for more details: http://msdn.microsoft.com/en-us/library/ms710922(VS.85).aspx.
A Paradox db file contains just one flat table. The actual structure of the DB file changed over time and different versions. But you can usually open the DB file with MS Excel - of course that changed over different versions too.
As noted above, other database applications, also including Paradox for Dos and Paradox for Windows, will open the file and other features as well. The key, for example is in the PX file with the same table name.
All of this assumes the table is not password protected, which an application database could be - or that you know the password. Beware if you get an error to that effect.
You can open and view Paradox database files using Database Desktop that is shipped with Borland C++Builder. A free alternative is BB's Database Desktop. The software may require administrator privileges to run correctly.
You can use gnumeric spreadsheet, paradox-db-reader or BB database desktop to read db paradox file.
BB database dekstop able to read XG0 file too.
BB's Database Desktop now called JEDI Database Desktop, but project is closed and it couldn't edit my table. I have had to use some hack: open *.db file in MS Excel 2007, edit it, export to *.csv, close file then Open *.db file in Paradox Data Editor 3.2.0, clear all table data and import previosly saved csv-file. And it works (don't know why but this app can't insert row in my file itself)!

Copy SQL Server MDF and LDF files while server is in use

I am using the following code to copy files from one folder to another...
Public Shared Sub CopyFlashScriptFile(ByVal SourceDirectory As String, ByVal DestinationDirectory As String)
Try
Dim f() As String = Directory.GetFiles(SourceDirectory)
For i As Integer = 0 To UBound(f)
File.Copy(f(i), DestinationDirectory & "\" & System.IO.Path.GetFileName(f(i)),True)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
The files I am copying are database files, .mdf and .ldf. Which are being used by the application. Now the problem is when I try to copy the files it throws an error
file is being used by another process
Can anyone help me with this?
Is there anyway I can programmatically stop SQL Server and copy the files, then start the server again?
To expand on my comment - I would build a .sql file with the T-SQL command to backup the database to another location, and then I can use sqlcmd from the command line in order to run the backup .sql file.
So to build the .sql file I would go through the process of backing up the database via SQL Server Management Studio. Here is a tutorial on how to do this:
http://www.serverintellect.com/support/sqlserver/database-backup-ssmse.aspx
Then, before clicking OK to perform the backup, click on the "Script" button on the backup window and choose "Script Action To New Query Window". This will generate the SQL of your settings from the backup database window. Save that SQL into a file and you're done.
Next is to use sqlcmd.exe to execute the .sql file to backup the database whenver you want. There is a very good example of using sqlcmd.exe from C# code here:
http://geekswithblogs.net/thomasweller/archive/2009/09/08/automating-database-script-execution.aspx
I always prefer doing stuff like this without affecting the running SQL Server (unless it's one running on my dev machine, where I'll happily stop/start the service). You just never what might happen if you stop a production SQL Server service to copy some files. Could be very costly, so better to be safe.
Depending on which version of SQL you are using you could make use of the Microsoft.SqlServer.Management.Smo.Wmi.Service objects to Start and Stop the Service that runs the SQL instance.
After doing this you should be able to simply copy the files as needed.
For SQL Server 2008
{
//Declare and create an instance of the ManagedComputer
//object that represents the WMI Provider services.
ManagedComputer mc;
mc = new ManagedComputer();
//Iterate through each service registered with the WMI Provider.
foreach (Service svc in mc.Services)
{
Console.WriteLine(svc.Name);
}
//Reference the Microsoft SQL Server service.
Service Mysvc = mc.Services["MSSQLSERVER"];
//Stop the service if it is running and report on the status
// continuously until it has stopped.
if (Mysvc.ServiceState == ServiceState.Running) {
Mysvc.Stop();
Console.WriteLine(string.Format("{0} service state is {1}", Mysvc.Name, Mysvc.ServiceState));
while (!(string.Format("{0}", Mysvc.ServiceState) == "Stopped")) {
Console.WriteLine(string.Format("{0}", Mysvc.ServiceState));
Mysvc.Refresh();
}
Console.WriteLine(string.Format("{0} service state is {1}", Mysvc.Name, Mysvc.ServiceState));
//Start the service and report on the status continuously
//until it has started.
Mysvc.Start();
while (!(string.Format("{0}", Mysvc.ServiceState) == "Running")) {
Console.WriteLine(string.Format("{0}", Mysvc.ServiceState));
Mysvc.Refresh();
}
Console.WriteLine(string.Format("{0} service state is {1}", Mysvc.Name, Mysvc.ServiceState));
Console.ReadLine();
}
else {
Console.WriteLine("SQL Server service is not running.");
Console.ReadLine();
}
}
From msdn
I am using the .mdf file in my application...in case of a system crash or format the user is going to loose the data..so if the user copies the data(.mdf) to some other drive ..he/she can replace the new .mdf file with the old one which has all there data...correct me if i am wrong...thanks.
That's exactly what "normal" backups are for.
As you noticed yourself, you can backup a SQL Server database by simply copying the .mdf and .ldf files, but the downside is that you can only do this when the SQL Server service is not running.
And stopping the SQL Server service just to backup the database is not a good idea, because your users can't access the database while the service is stopped.
Taking a "normal" backup (usually a .bak file) can be done while the database is running, so there's no need to stop SQL Server every time you want to make a backup.
There are several ways how to do a backup:
a) Manually in SQL Server Management Studio:
see the first link in Jason Evans' answer
b) If you want to take a backup regularly (say, once a day) you need to use sqlcmd.
Jason Evans described this in his answer as well, but IMO there's an easier way - you need only two files with one line each. See How to create jobs in SQL Server Express edition.
(if you were using a full SQL Server edition and not only Express, you could set up a Maintenance Task in Management Studio instead, but that's not possible in SQL Server Express, so you have to do it manually like described above).

I would like to extract the SQL queries from Crystal Report .rpt files, is there a way to do this?

I would like to extract the SQL queries from Crystal Report .rpt files, is there a way to do this?
I don't have any of the Crystal Reports products, just the .rpt files.
Here's a .Net example of code that grabs the Command Sql from all Crystal Reports in a given directory. It requires the Crystal 2008 .Net SDK to be installed (you can download a trial from SAP):
foreach (string file in Directory.GetFiles("c:\\projects\\Reports", "*.rpt"))
{
Console.WriteLine(String.Format("Processing {0}...", file));
var doc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
doc.Load(file);
foreach (dynamic table in doc.ReportClientDocument.DatabaseController.Database.Tables)
{
if (table.ClassName == "CrystalReports.CommandTable")
{
string commandSql = table.CommandText;
//TODO: do something with commandSql
}
}
}
To get the SQL as Crystal would build it when running a report, see this link: SAP Note 1280515 - How to extract SQL query from Crystal reports using RAS sdk.
I believe to do this, you need to supply the report parameter values so that Crystal can connect to the database in order to build the SQL. In the example, since a Report Viewer control is used, Crystal can prompt the user for the parameters.
In "Crystal Reports ActiveX Designer Design and Runtime Library" (craxddrt.dll), the Report.SQLQueryString property will do what you want.
I can't seem to find an equivalent property in the .Net SDK, and believe me, I've been looking.
** edit **
It appears that one can make use of the In-Process RAS Server to get this information:
CrystalDecisions.ReportAppServer.DataDefModel.CommandTableClass.CommandText
The other way around this is if you can run the reports, you can hook up SQL Profiler to your DB and capture the incoming SQL on the database side.
JoshL's answer worked for several of my reports, but not all of them. The following method, using ReportClientDocument.RowsetController.GetSQLStatement, was able to extract some of the queries that the other method missed.
foreach (string file in Directory.GetFiles("c:\\projects\\Reports", "*.rpt"))
{
Console.WriteLine(String.Format("Processing {0}...", file));
var doc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
doc.Load(file);
var controller = doc.ReportClientDocument.RowsetController;
var groupPath = new CrystalDecisions.ReportAppServer.DataDefModel.GroupPath();
string temp = String.Empty;
string commandSql = controller.GetSQLStatement(groupPath, out temp);
//TODO: do something with commandSql
}
My experience is with older versions of Crystal (8,9) - I've no idea what the file formats look like for more recent versions. However, it's worth opening the files up in a text editor just in case, but for the file formats I've seen, the query text is not accessible this way.
If I remember correctly, some versions of Visual Studio 2003 came with tools for manipulating Crystal .rpt files (but I guess this isn't of much use to you, since if you had this already, you wouldn't be asking!).
It's not a very imaginative suggestion, but perhaps your quickest route would be to download the 30-day trial version of the current Crystal Reports, and see if that will open the files for you.
In the Visual studio, select the .rpt file and Go to field explorer, right click on DatabaseFields. Click on SQL query option to view the query.