Let me add a quick explanation to this post:
I am using visual studio and if I create a connection to a database it works. I can query the database through the database designer (The one where you see the tables and can create new queries) and the data processes correctly.
HOWEVER even using this route I am getting the same sql exception. To me this says something in visual studio is not set up correctly however I could be wrong.
I am using the following code to connect to a database on my server (with using System.Data.SqlClient; at the top):
SqlConnection thisConnection = new SqlConnection();
thisConnection.ConnectionString =
"Data Source=192.168.0.0,1433;" +
"Initial Catalog=test-db;" +
"User Id=UserName;" +
"Password=Password;";
thisConnection.Open();
And I am getting the following error:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, TdsParserState state)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, TdsParserState state)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Connect(String host, SqlInternalConnection connHandler, Int32 timeout)
at System.Data.SqlClient.SqlInternalConnection.OpenAndLogin()
at System.Data.SqlClient.SqlInternalConnection..ctor(SqlConnection connection, Hashtable connectionOptions)
at System.Data.SqlClient.SqlConnection.Open()
at InventoryControl.Login.validUserName()
at InventoryControl.Login.LoginButton_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.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
at System.Windows.Forms.Application.Run(Form fm)
at InventoryControl.Program.Main()
If you have any idea how to resolve this it would be greatly appreciated!
Exception is below:
System.Data.SqlClient.SqlError: SQL Server does not exist or access denied
However I am positive I have permission to this server as I can access it and query it in visual studio.