简体   繁体   English

用户登录失败-Visual Basic和SQL Server 2008

[英]Login failed for user - Visual basic and SQL server 2008

I am quite new to visual basic bear with me. 我对视觉基础感到很陌生。 I have created a windows application using visual studio 2010 and SQL server 2008. I am getting login problems when trying to execute an insert SQL command. 我已经使用Visual Studio 2010和SQL Server 2008创建了Windows应用程序。尝试执行插入SQL命令时遇到登录问题。 I have given user an owner privilege. 我已授予用户所有者权限。 This is connection string I am using. 这是我正在使用的连接字符串。

Data Source= ServName ;Initial Catalog=  DBName ; Integrated Security=True


System.Data.SqlClient.SqlException (0x80131904): Cannot open database "DbName" requested by the login. The login failed.
Login failed for user 'UserID'.
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at DataUploader.Buffer.UploadtoMainDB(String ConStr)
   at DataLoader.Fr_CheckDuplicate.Button4_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Thanks for your help in advance. 感谢您的帮助。

Two things I notice. 我注意到两件事。 First the error message is saying that the user you are trying to login with is 'UserId'. 首先,错误消息说您尝试登录的用户是'UserId'。 Is that really the name of your user? 那真的是您的用户名吗? My guess is that it is not. 我的猜测是事实并非如此。 Second it appears that you have defined your connection string incorrectly. 其次,似乎您定义了错误的连接字符串。

Your connection string should look like this: 您的连接字符串应如下所示:

 Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;

Additionally I would try logging into your SQL Server with the username and password you are using in the connection string first. 另外,我会尝试首先使用您在连接字符串中使用的用户名和密码登录到SQL Server。 This will allow you to tweak any necessary permissions with the login without needing to start and stop your application. 这样一来,您就可以调整登录信息的所有必要权限,而无需启动和停止应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Visual Studio 上远程连接到 SQL server2008 express 失败 - RemoteConnection to SQL server2008 express failed on Visual Studio Visual Studio Server Explorer错误:用户DOMAIN \\ USERNAME的登录失败 - Visual Studio Server Explorer Error: Login failed for user DOMAIN\USERNAME 如何使用SQL Server 2008数据库为我的Visual Basic项目创建安装程序? - How to create installer for my visual basic project with sql server 2008 database? Visual Studio和SQL Server 2008错误 - Error with Visual Studio and SQL Server 2008 从 Visual Basic 连接到 Microsoft SQL Server - Connecting to Microsoft SQL Server from Visual Basic 在Visual Basic 2010中提示SQL Server连接 - Prompt for SQL Server to connect to in Visual Basic 2010 SQL Server上的Visual Basic 2010登录错误 - Visual Basic 2010 Log in Error on SQL Server 使用Linq-To-SQL的SQL Server 2000数据库上的用户“ sa”登录失败 - Login Failed for user “sa” on SQL Server 2000 database using Linq-To-SQL 单用户登录带有MYSQL数据库的Visual Basic Desktop应用程序 - Single User login Visual Basic Desktop application with MYSQL Database ASP.NET MVC2.0远程SQL Server-用户“”登录失败 <username> &#39;。 原因:不与受信任的SQL Server连接关联 - ASP.NET MVC2.0 remote SQL server - Login failed for user '<username>'. Reason: Not associated with a trusted SQL Server connection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM