[英]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.