SQL Server Express "Error: 26-Error Locating Server/Instance Specified) - sql

I just created a Windows forms application with SQL Server 2008. I created the Setup File and installed the application.
When I click on any forms from the menu it shows an error
a network related or instance specific error occurs.
And hence couldn't find the server and so.
I guess I have done something wrong in connection string
Here is my connection string
Dim constr As String = "Data Source= server=.\SQLEXPRESS;AttachDbFilename=" & Application.StartupPath & "\jshed.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
Can somebody help me?

remove the following from the connection string
server=
try this
Dim constr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & Application.StartupPath & "\jshed.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

Related

Running published project in other computer

I have done developing and tried debugger and the code run fine in my laptop, but when Publishing or even using Release mode and than using it in other computers it show null exception
in this part of code
For Each r As DataRow In Access.dbDataTable.Rows
Check = r("EmployeeType")
Next
this one used in login Form and yes I forget to mention I use Access DB
I am really confused it's work fine than why it show exception
by the way my connection string
Dim mypath = Application.StartupPath & "\test.accdb"
Dim mypassword = "test"
Private dbConnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & mypath & ";Jet OLEDB:Database Password=" & mypassword)
exception shown is NullRefrenceException
I have solved the problem if anyone got same problem
try to check the version of ms access it should have same version
also check connection string
Private dbConnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & mypath & ";Jet OLEDB:Database Password=" & mypassword)
Microsoft.ACE.OLEDB.12.0 Need to be changed to same version of ms access targeted PC

External table is not in the expected format error while trying to access Excel

I am trying to access Excel from my vb application by using the Oledb Connection .
Here is my connection string:
<add key="ExcelConnection" value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties="Excel 12.0 Xml;HDR=NO;IMEX=1;MAXSCANROWS=1000;READONLY=FALSE;"" />
Here is the code:
Dim connection As New System.Data.OleDb.OleDbConnection(ExcelConnectionString)
connection .Open()
Dim schTbl As DataTable = connection .GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, Nothing)
Dim dbAdapter As System.Data.OleDb.OleDbDataAdapter
Dim execQuery As String
Dim rtnData As System.Data.DataTable
execQuery = "SELECT * FROM [" & schTbl.Rows.Item(0)("TABLE_NAME") & "]"
dbAdapter = New System.Data.OleDb.OleDbDataAdapter(execQuery , ExcelConnectionString)
dbAdapter.Fill(rtnDat )
dbAdapter.Dispose()
connection .Close()
schTbl .Reset()
What my problem is that ,the above is working 70% of the times but rest of the times i am getting the following error:
System.Data.OleDb.OleDbException (0x80004005): External table is not in the expected format.
Could anyone please help me that why at times i am getting this error .Is there any way to rectify it or any other way to achive the same result.
Any help will be appreciated.
Thanks
External table is not in the expected format. typically occurs when trying to use an Excel 2007 file.
Using the following connection string seems to fix most problems.
dim path as string = yourfilepath
dim connStr as string = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;"
Edit
some times this too may fail in a case when your are using an .xlsx file.if that is the case you should install a JET database engine in your pc to override those errors.it is availale http://www.microsoft.com/downloads/details.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891&displaylang=en

Error 1 Character constant must contain exactly one character

i wanted to open a myconnection but there is an error in my connection string. I need help in changing character or how to solve that error in my connection string?. pls help.
following is the code i am using
Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename="c:\users\samsung\documents\visual studio 2010\Projects\WindowsApplication2\WindowsApplication2\Database1.mdf";Integrated Security=True;User Instance=True")
ur help is greatly appreciated. thanks
change your connection string as follows:
Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=" & _
"c:\users\samsung\documents\visual studio 2010\Projects\WindowsApplication2\WindowsApplication2\Database1.mdf;" & _
"Integrated Security=True;User Instance=True")
or you can do like this also
Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=c:\users\samsung\documents\visual studio 2010\Projects\WindowsApplication2\WindowsApplication2\Database1.mdf;Integrated Security=True;User Instance=True")

Visual Studio 2012- Connection to local db (error 26)

super new to Visual Studios and i need some help with regards to connection to database.
I only have visual studios 2012 installed.
So I'm trying to create a simple sign up form, and storing the information into a table(created a local database for this with the table 'Users'.)
The problem is:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or is not accessible. Verify that the instance name is correct and that SQL Server name is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified.)
Er, so what should I do? :(
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Try
con.ConnectionString = "Data Source=|DataDirectory|\Database1.sdf;"
con.Open()
cmd.Connection = con
Dim sha1 As SHA1 = sha1.Create()
Dim password As Byte() = sha1.ComputeHash(Encoding.Unicode.GetBytes(password1.Text))
cmd.CommandText = "INSERT INTO users (username,password) VALUES('" & username1.Text & "','" & password1.Text & "');"
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Error : " & ex.Message, "insert data")
Finally
con.Close()
End Try
Thanks guys.
EDIT:
Sad to say , I dont have any SQLExpress here in my laptop. so Yeahhh.
This might happen due to the SQLExpress has been stopped...Try to start it manually by going to services

vb.net Oracle connection using TNS Name?

I have put my tns connection into the .ora file and am now able to conenct to it using SQL plus and can ping it :tnsping myConn.
I've also added the connection to the ODBC Manager and connecting successfully when tetsing conneciton through the ODBC tool.
now i'm having an issue making a connection to it using vb.net
i've tried the following:
oODBCConnection = New Odbc.OdbcConnection(connStr)
oODBCConnection.Open()
where my connStr is:
Data Source=tns.dev;User Id=MyUser;Password=MyPass;
per: http://www.connectionstrings.com/oracle and http://www.shabdar.org/c-sharp/101-connect-to-oracle-using-asp-net-and-csharp.html
what am i doing wrong? it's telling me i need to specify a driver, how do i do it?
Thank you!
the error i'm getting is:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Did you checked the tnsnames.ora file? Is there any entry for tns.dev?
http://www.mike-devlin.com/oracle/tnsnames_ora.htm
That is not an oracle error - it sounds like you did not create a system dsn. This code looks like it expects a DSN by name of tns.dev.
That said, I would not use odbc if I could help it. You might want to look at Oracle Data Provider for .net
http://www.oracle.com/technetwork/topics/dotnet/index-085163.html
ODBCConnection was incorrect.
solution:
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim myConnection As New OracleConnection(connStr)
myConnection.Open()
I´ve been using the following code in Vb.net
Dim conn As New Odbc.OdbcConnection
Dim cmd As New Odbc.OdbcCommand
Dim drResult As Odbc.OdbcDataReader
Dim connString As String
Dim QuerySQL As String
connString = "Driver={Microsoft ODBC for Oracle};CONNECTSTRING=(DESCRIPTION=(ADDRESS= (PROTOCOL=TCP)(HOST=ORACLEDB01)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE_INSTANCE_NAME)));Uid=john;Pwd=mypassword;"
QuerySQL = "select first_name, last_name from employees where id = 28"
conn.ConnectionString = connString
conn.Open()
cmd.Connection = conn
cmd.CommandText = QuerySQL
drResult = cmd.ExecuteReader()
While drResult.Read
TextBox1.Text = TextBox1.Text & drResult("last_name") & ", " & drResult("first_name") & Environment.Newline
End While
drResult.Close()