以编程方式创建登录

以编程方式创建登录

本文介绍了以编程方式创建登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天好友。



我有问题,希望你们能帮助我。



我正在处理连接到ms sql server的VB.NET 2012应用程序。我想允许用户选择已安装的服务器实例,因此我有一个模块,显示已安装的服务器实例供用户选择。



选择后然后,模块将创建必要的数据库对象。我的代码在尝试为当前用户创建ms sql登录时引发错误。我发现connectiontring(firstSQL)引发了错误,但我不知道解决它。



请查看我的代码的以下详细信息。

Good day buddies.

Please I have a problem and I hope you guys can help me out.

I am working on VB.NET 2012 application that connects to ms sql server. I want to allow users to select the installed sever instance of their chioce so I have a module that present installed server instances for the user to select from.

After a selection is made, the module will then create the necessary database objects. My code raise error when it tries to create ms sql login in for the current user. I found that the error is raised by connectionstring(firstSQL) but I do not know to resolve it.

Please find below details of my code.





connectionStr = "Data Source=" & lstLocalSevers.SelectedItem.ToString & ";DataBase=;Integrated Security=SSPI"

Dim firstSQL As New SqlConnection(connectionStr)


<pre>'create login for the current user
Dim sql As New SqlCommand("if not exists (select NAME FROM sys.login_token" & ")  CREATE LOGIN " & us, firstSQL)
            sql.ExecuteNonQuery()







错误:'语法不正确' - '。 ' - '是计算机名称(name-PC)的一部分,实例是name-PC\SQLEXPRESS,从pc生成的onnection字符串是'




The error: 'Incorrect syntax near '-'. The '-' is part of the computer name(name-PC) and the instance is name-PC\SQLEXPRESS and the onnection string generate from the pc is '

"Data Source=name-PC\SQLEXPRESS;DataBase=;Integrated Security=SSPI"

'





预先感谢您的帮助

'


Thanks in advance for your help

推荐答案


这篇关于以编程方式创建登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 00:19