I have been trying to fix a project which already use a 100% connections to Oracle. They are trying to upgrade the project to start using SQL Server 2012 Management Studio. But I'm having issues connecting to the database. We use Windows authentication.
I can login fine directly to SQL Server 2012 using Management Studio and Windows authentication. If I create a fresh new WindowsApplication1 project to test the connection code it works fine, I'm using this code (and get an error is at conn.Open()):
Imports System.Data.SqlClient
Public Class Open_Filing_Image
'Create ADO.NET objects.
Private myConn As SqlConnection
Private myCmd As SqlCommand
Private myReader As SqlDataReader
Private results As String
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'Create a Connection object.
Dim connStr As [String] = "Server=servername; Database=dbname; Integrated Security=True"
myConn = New SqlConnection(connStr)
'Create a Command object.
myCmd = myConn.CreateCommand
myCmd.CommandText = "SELECT DdocName FROM dbo.Document WHERE XAlaskaID = '72010' and DdocType = 'Filings'"
'Open the connection.
Try
myConn.Open()
MsgBox("Connection Open ! ")
Catch ex As Exception
MsgBox("Can not open connection ! ")
End Try
myReader = myCmd.ExecuteReader()
'Concatenate the query result into a string.
Do While myReader.Read()
results = myReader.GetValue(0)
Loop
'Display results.
Dim documentID As String = results
Dim outPath As String = "http://address.internet`enter code here`/" + documentID + (".pdf")
System.Diagnostics.Process.Start(outPath)
'Close the reader and the database connection.
myReader.Close()
myConn.Close()
End Sub
End Class
Error message:
A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The specified data could not be decrypted.
Thank you.
Fix it doing some research and some assistance by another programmer:
The project had a Bcrypt reference that block the connections to SQL. I delete all Bcrypt and add transport credentials to Windows in the app.config. any way thanks guys.
Related
Sorry if i am posting this in the wrong section, i have no idea how any of this works and am a total noob to coding. I am however passionate and would like some help. I will respond quickly to any questions you guys may have so i can provide further information. Without further ado, here is my code. I will explain the issue below.
Imports System.Data.SqlClient
Imports System.Data
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connection As New SqlConnection("Server = M's PC; Database = tyre_stocks_database_plain1.accdb; Integrated Security = true")
Dim command As New SqlCommand("select * from Login_info where Username = #Username and Password = #Password", connection)
command.Parameters.Add("#Username", SqlDbType.VarChar).Value = TextBoxUsername.Text.ToString()
command.Parameters.Add("#Password", SqlDbType.VarChar).Value = TextBoxPassword.Text.ToString()
Dim adapter As New SqlDataAdapter(command)
Dim table As New DataTable()
adapter.Fill(table)
If table.Rows.Count() <= 0 Then
MessageBox.Show("Username Or Password Is Invalid")
Else
MessageBox.Show("Login Successful")
End If
End Sub
End Class
I am getting an error to do with "adapter.Fill(table)". The program states:
"System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'"
If it is still a bit unclear, i am trying to create a login page that "allows entry" to the user, provided they have the correct username and password that is stored in the database.
I have made sure that the connection to my Microsoft Access database is active by checking for the green plug sign next to the database name. If anyone could provide any information on how to help whatsoever i would be very grateful. Please bare in mind i am extremely new to coding and thus a total noob (as previously mentioned :P) i will respond promptly to any questions as to provide further information. Thank you fellow coders !
You didn't give the adapter the connection needed.
Dim adapter As New SqlDataAdapter(command, connection)
your code was missing Connection parameter. check line 15 where you need to supply the connection. Second thing is to check your connection string , it should have valid server and database names.
Imports System.Data.SqlClient
Imports System.Data
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connection As New SqlConnection("Server = M's PC; Database = tyre_stocks_database_plain1.accdb; Integrated Security = true")
Dim command As New SqlCommand("select * from Login_info where Username = #Username and Password = #Password", connection)
command.Parameters.Add("#Username", SqlDbType.VarChar).Value = TextBoxUsername.Text.ToString()
command.Parameters.Add("#Password", SqlDbType.VarChar).Value = TextBoxPassword.Text.ToString()
Dim adapter As New SqlDataAdapter(command, connection)
Dim table As New DataTable()
adapter.Fill(table)
If table.Rows.Count() <= 0 Then
MessageBox.Show("Username Or Password Is Invalid")
Else
MessageBox.Show("Login Successful")
End If
End Sub
End Class
Using Visual Studio 2010 I am able to start a new project using ADODB (Microsoft ActiveX Data Objects 6.1 Library COM 6.1.0.0) to connect to MS Access and SQL Server, save the project, re-open the project and it all works as expected. BUT when I do this trying to connect to a SQL Server Instance it will work until I save the project after which I always get the error: "SQL Server does not exist or access denied".
Here is the code for my test console application;
Module Module1
Sub Main()
Dim cn As New ADODB.Connection()
Dim rs As New ADODB.Recordset()
Dim cnStr As String
' Modify this connection string to reflect your server and logon information.
' Store the connection to a variable to be used throughout this example.
cnStr = "Provider=SQLOLEDB;Initial Catalog=Firehouse;Data Source=devclstr\devclstr;" & _
"User ID=xxx;Password=xxx;"
' 1. Connect through the Connectionstring property.
cn.ConnectionString = cnStr
cn.Open()
rs.Open("select * from usr_sec", cn)
Dim da As New System.Data.OleDb.OleDbDataAdapter()
Dim ds As New DataSet()
da.Fill(ds, rs, "products")
Console.Write("There are " & ds.Tables(0).Rows.Count.ToString & " total users.")
Console.ReadLine()
rs = Nothing
cn.Close()
cn = Nothing
End Sub
End Module
This will work only in the following scenario: start new console project, enter the code, add the "ActiveX Data Objects 6.1 Library" reference, and it runs as expected. As soon as I save it each subsequent execution gives me the following error:
System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2147467259
HResult=-2147467259
Message=[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
Source=Microsoft OLE DB Provider for SQL Server
StackTrace: at ADODB._Connection.Open(String ConnectionString, String UserID, String Password, Int32 Options)
Please share any insight in how to resolve this problem
Normally, I'd advise against using the COM approach, when there are built in connectors, so instead, something like:
Imports System.Data.SqlClient;
Module Module1
Sub Main()
' Modify this connection string to reflect your server and logon information.
Dim cnStr As String = "Initial Catalog=Firehouse;Data Source=devclstr\devclstr;User ID=xxx;Password=xxx;"
Using con as New SqlConnection(cnStr)
con.Open()
Using cmd as New SqlCommand("select * from usr_sec", con)
Using da As New SqlDbDataAdapter()
Dim ds As New DataSet()
da.Fill(ds, rs, "products")
Console.Write(String.Format("There are {0} total users.", ds.Tables(0).Rows.Count))
Console.ReadLine()
End Using
End Using
End Using
End Sub
End Module
I have worked on visual studio 08 as an undergrad and i want to start developing my then project in visual studio 12 . How can i do that ... There is no option to import .mdf files.
any help will be appreaciated.
I got the answer to the above question , i connected the data base , but how ever its gives me an error when i run the code .
I am trying to make a web application in visual basic .
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Conn As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim password As String
password = Encrypt(TextBox2.Text, "&%##?,:*")
'Queries
Dim query As String = "select * from Registration where username='" & TextBox1.Text & "' and password='" & password & "'"
Dim SQLConn As New SqlConnection(Conn)
Dim SQLCmd As New SqlCommand(query, SQLConn)
SQLConn.Open()
Dim dr As SqlDataReader
dr = SQLCmd.ExecuteReader()
dr.Read()
' If Present in databse it will enter here
If dr.HasRows Then
' Remember Session
'Session("viewid") = dr("userid")
Session("userid") = dr("userid")
Session("username") = dr("username")
Session("email") = dr("email")
'Remember Me on this pc
If CheckBox1.Checked Then
Response.Cookies("UserName").Value = dr("username")
Response.Cookies("UserName").Expires = DateTime.Now.AddMonths(1)
End If
Response.Redirect("Home.aspx")
End If
SQLConn.Close()
Label4.Text = "* Incorrect Username/ Password/ Mode. Re-enter!"
End Sub
It gives me an error at SQLConn.Open():
SqlException was unhandled by user code
The user instance login flag is not allowed when connecting to a user instance of SQL Server. The connection will be closed.
Can someone tell me what need to be done ?
I suppose you try to attach your DB file on SQL Server? There was a similar problem under Windows 7, which was cause by invalid security rights when installing SQL.
The workaround was to delete a directory, which is automatically recreated if missing:
Delete C:\Documents and Settings\USERNAME\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS.
But I really don't know if it is the same cause on Win8.
Hope this helps
Serge
I have the following code:
Dim string_conectare As String = "Data Source=|DataDirectory|\Database1.sdf"
Dim conexiune As SqlConnection
conexiune = New SqlConnection(string_conectare)
conexiune.Open()
If conexiune.State = ConnectionState.Open Then
MsgBox("OK")
Else
MsgBox("not ok")
End If
As you can see i would like to open a connection to the database but every time I want test it I get this error:
A network-related or instance-specific error occurred while establishing a
connection to SQL Server. The server was not found or was not accessible.
Verify that the instance name is correct and that SQL Server is
configured to allow remote connections. (provider: SQL Network Interfaces,
error: 26 - Error Locating Server/Instance Specified)
I struggled for more than 2 hours, so please help me!
Later edit:
I've tried this:
Dim string_conectare As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Database1.sdf;Persist Security Info=True"
Dim conexiune As OleDbConnection
conexiune = New OleDbConnection(string_conectare)
conexiune.Open()
If conexiune.State = ConnectionState.Open Then
MsgBox("OK")
Else
MsgBox("not ok")
End If
but it throw me this error:
Unrecognized database format
Here is an excerpt of the same code I use to connect to my databases:
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim conn As MySqlConnection
'Connect to the database using these credentials
conn = New MySqlConnection
conn.ConnectionString = "server=your server site (generally long url); user id=login id for mysql user; password=self explanatory; database=name of the DB you're trying to reach"
'Try and connect (conn.open)
Try
conn.Open()
Catch myerror As MySqlException 'If it fails do this... (i.e. no internet connection, etc.)
MsgBox("Error connecting to database. Check your internet connection.", MsgBoxStyle.Critical)
End Try
'MySQL query (where to call for information)
Dim myAdapter As New MySqlDataAdapter
'Tell where to find the file with the emails/passes stored
Dim sqlquery = "SELECT * FROM the database you selected above WHERE Email = '" & txtEmail.Text & "' AND Password = '" & txtPassword.Text & "'"
Dim myCommand As New MySqlCommand
myCommand.Connection = conn
myCommand.CommandText = sqlquery
'Start query
myAdapter.SelectCommand = myCommand
Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader
If myData.HasRows = 0 Then
MsgBox("Invalid email address or password.", MsgBoxStyle.Critical)
Else
MsgBox("Logged in as " & txtEmail.Text & ".", MsgBoxStyle.Information)
Me.Close()
End If
End Sub
Try that.
Be sure to add the resource MySQL.Data into your project and also call it using:
Imports MySQL.Data.MySQLClient
ALSO! Be certain that when you created the database that you enabled external database access. If you don't do that then VB programs will not be able to access it and it will limit access to your webhost only.
The Jet OLEDB Provider is for Access databases. It can't handle sdf files. Try with the correct connection string.
You can take help of this website to get the correct connection string for your database:
www.ConnectionStrings.com
Is the application built on shared storage and you are trying to run it from local machine?
That could be an issue if the server containing the app does not have access to db
I'm trying to connect to a SQL server from VB. The SQL server is across the network uses my windows login for authentication.
I can access the server using the following python code:
import odbc
conn = odbc.odbc('SignInspection')
c = conn.cursor()
c.execute("SELECT * FROM list_domain")
c.fetchone()
This code works fine, returning the first result of the SELECT. However, I've been trying to use the SqlClient.SqlConnection in VB, and it fails to connect. I've tried several different connection strings but this is the current code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As New SqlClient.SqlConnection
conn.ConnectionString = "data source=signinspection;initial catalog=signinspection;integrated security=SSPI"
Try
conn.Open()
MessageBox.Show("Sweet Success")
''#Insert some code here, woo
Catch ex As Exception
MessageBox.Show("Failed to connect to data source.")
MessageBox.Show(ex.ToString())
Finally
conn.Close()
End Try
End Sub
It fails miserably, and it gives me an error that says "A network-related or instance-specific error occurred... (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
I'm fairly certain it's my connection string, but nothing I've found has given me any solid examples (server=mySQLServer is not a solid example) of what I need to use.
Thanks!
-Wayne
You are using an ODBC DSN as a SqlClient server name. This is not going to work. You have to use a SqlClient connection string, and for SqlClient the DataSource property is the server name or a SQL Native Client server alias (which is not the same as an ODBC DSN).
Replace signinspection with the actual name of your SQL Server host. If is a named instance or listening on a non default port, you have to specify that too, eg: hostname\instancename
Check out connectionstrings.com for samples. It looks like in your python example, you are accessing the DB via ODBC.
The string you are using is connecting with the built in .NET SQL Server DB provider, so you need to use an ODBC connection string OR change your data source to the actual server name (if no other instances) or servername/instance name.
Sure your Server and Database have the same name?
Here you have a link that would allow you to generate a connection string and test it
http://blogs.msdn.com/dhejo_vanissery/archive/2007/09/07/One-minute-Connection-string.aspx.
Well, I went ahead and used an ODBC Connection. It appears that that is what I was wanting in the first place.
In order to do use the ODBC I had to go to http://support.microsoft.com/kb/310985 and install a few files. Following the directions I came up with the following code that seems to work just fine:
Dim conn As OdbcConnection
conn = New OdbcConnection("DSN=SignInspection")
Dim mystring as String = "SELECT * FROM list_domain"
Dim cmd As OdbcCommand = New OdbcCommand(mystring, conn)
Dim reader As OdbcDataReader
Dim columnCount As Integer
Dim output As String
Dim data as Object() = New Object(10) {}
conn.Open()
MsgBox("Connected!")
reader = cmd.ExecuteReader()
While reader.Read()
columnCount = reader.GetValues(data)
output = ""
For i As Integer = 0 To columnCount - 1
output = output & " " & data(i).ToString()
Next
Debug.WriteLine(output)
End While
conn.Close()
Of course I'll have it cleaned up a lot, but I figure maybe someone will end up looking for the same solution, and maybe they'll see my code before they spend too much time.
ed. columsCount -> columCount
You might want to take a look on Microsoft Enterprise Library Data Access Application Block in order to make it easier to connect and to support multiple underlying datastores.
Good success! =)