使用sqlcmd连接到Azure [英] Connecting to Azure with sqlcmd

查看:81
本文介绍了使用sqlcmd连接到Azure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从sqlcmd连接到SQL数据库。我可以这样做,但我能连接的唯一数据库是master。 
$
我一直得到: 

Sqlcmd:错误:用于SQL Server的Microsoft ODBC驱动程序17 :用户'iptadmin'登录失败。 
$
Sqlcmd:错误:用于SQL Server的Microsoft ODBC驱动程序17:无法打开数据库"导入"登录请求。登录失败.. 
$


我的命令是:sqlcmd -S ipthealthcare.database.windows.net -U iptadmin -P xxxxxx -d Import 

其中Import是我创建的新数据库,我想连接到。 
$
如果我没有指定'-d Import',它会将我登录到master数据库。 />


当我使用SSMS时,我在初始登录到master时没有问题,那么我可以从下拉列表中更改数据库。



如何更改/添加iptadmin登录的权限,以便它登录的默认数据库不是主数据库而是导入?

I need to connect to a SQL database from sqlcmd. I can do that, but the only database I can connect is master. 
I keep getting : 
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'iptadmin'.. 
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Cannot open database "Import" requested by the login. The login failed.. 

My command is: sqlcmd -S ipthealthcare.database.windows.net -U iptadmin -P xxxxxx -d Import 
where Import is the new database I created and I want to connect to. 
If I do not specify '-d Import' it logs me into the master database.

When I use SSMS I have not problems in logging initially into master then I can change the database from the dropdown.

How can I change/add privileges to the iptadmin login so that the default database it logs into is not master but Import?

推荐答案

我需要从sqlcmd连接到SQL数据库。我可以这样做,但我能连接的唯一数据库是master。 
$
我一直得到: 

Sqlcmd:错误:用于SQL Server的Microsoft ODBC驱动程序17 :用户'iptadmin'登录失败。 
$
Sqlcmd:错误:用于SQL Server的Microsoft ODBC驱动程序17:无法打开数据库"导入"登录请求。登录失败.. 
$


我的命令是:sqlcmd -S ipthealthcare.database.windows.net -U iptadmin -P xxxxxx -d Import 

其中Import是我创建的新数据库,我想连接到。 
$
如果我没有指定'-d Import',它会将我登录到master数据库。 />


当我使用SSMS时,我在初始登录到master时没有问题,那么我可以从下拉列表中更改数据库。



如何更改/添加iptadmin登录的权限,以便它登录的默认数据库不是主数据库而是导入?
I need to connect to a SQL database from sqlcmd. I can do that, but the only database I can connect is master. 
I keep getting : 
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'iptadmin'.. 
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Cannot open database "Import" requested by the login. The login failed.. 

My command is: sqlcmd -S ipthealthcare.database.windows.net -U iptadmin -P xxxxxx -d Import 
where Import is the new database I created and I want to connect to. 
If I do not specify '-d Import' it logs me into the master database.

When I use SSMS I have not problems in logging initially into master then I can change the database from the dropdown.

How can I change/add privileges to the iptadmin login so that the default database it logs into is not master but Import?

美好的一天,

1。使用  sqlcmd

1. Make sure that you use CMD shell and not PowerShell when you use sqlcmd

时,请确保使用CMD shell而非PowerShell *您可以执行命令:" cmd"为了使用PowerShell窗口从PowerShell更改为CMD shell

* You can execute the command: "cmd" in order to change from PowerShell to CMD shell, using the PowerShell window

2。您是否在该数据库中有一个与LOGIN相关的USER?

2. Do you have a USER in that database which related to the LOGIN?

如果没有,那么在数据库中创建新的USER以便使用该数据库login

If not then CREATE new USER in the database in order to use that database with that login

-- CONNECT TO master using the sysadmin:
CREATE LOGIN MyTestLogin WITH PASSWORD = 'My!Test@Login'
GO

-- Connect the specific database using the sysadmin in order to create USER in the database
CREATE USER MyTestUser FOR LOGIN MyTestLogin
GO

-- You might want to make the user owner on the database?!?
-- Or GRANT him the specific permissions which he need
EXEC sp_addrolemember N'db_owner', N'MyTestUser'
GO

-- Now you can use the LOGIN information in order to connect the DATABASE

  

  


这篇关于使用sqlcmd连接到Azure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆