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")
Related
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"
I am trying to connect Visual Basic to MS Access using ADODB. But as I execute my code, it prompts: "Provider cannot be found.It may not be installed properly." But when I check on my directory I've got my "msjetoledb40.dll" installed.
Here is my code:
Dim conn As ADODB.Connection, rec As ADODB.Recordset
Sub sample()
Set conn = New ADODB.Connection
conn.Open ("Provider=Microsoft.Jet.OLEDB 4.0;Data Source=C:\sample.mdb;Persist Security Info=false;")
End Sub
This would be better:
Sub sample()
Dim conn As ADODB.Connection, rec As ADODB.Recordset
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\sample.mdb;"
conn.Open
End Sub
You missed a point.
Microsoft.Jet.OLEDB 4.0 => Microsoft.Jet.OLEDB.4.0
Ref: http://www.connectionstrings.com/.
Confirming the version of your MS Office on which the script is running. If you have installed MS Office 2013 or later, you should revise the connection string from:
Provider=Microsoft.Jet.OLEDB 4.0;Data Source=C:\sample.mdb;Persist Security Info=false;
to:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\sample.mdb;Persist Security Info=false;
At least, this sovled my problem.
My solution:
Error 3706
cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & sPath & ";Persist Security Info=False;"
Just Change 12.0 for 15.0
cs = "Provider=Microsoft.ACE.OLEDB.15.0;Data Source=" & sPath & ";Persist Security Info=False;"
and works, always you must to try change the version of the controller!.
i want to create a connection to my database in my application on vb.net
i stored a procedure called "CTable" that will create tables if they don't exist
im using this code:
Dim strConnection As String
strConnection = "Data Source=Localhost; Initial Calalog=Northwind; Integrated Security=True"
Dim MyConn As SqlConnection
Dim cmd As SqlCommand
MyConn = New SqlConnection(strConnection)
Dim query As String = "EXEC CTable"
cmd = New SqlCommand(query, MyConn)
MyConn.Open()
cmd.ExecuteNonQuery()
MyConn.Close()
but he is giving this error:
" An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll
Additional information: Keyword not supported: 'initial calalog'"
my question is : what should i put in my 'strConnection' variable to be able to execute my CTable Procedure????
You have a typo in the connection string. Try "Catalog" instead of "Calalog" ;)
The word is Catalog not Calalog.
So this should work:
strConnection = "Data Source=Localhost; Initial Catalog=Northwind; Integrated Security=True"
Note that you also have to set the CommandType to CommandType.StoredProcedure.
But always use the Using statement to ensure that unmanaged resources are disposed even on error:
Dim strConnection = "Data Source=Localhost; Initial Catalog=Northwind; Integrated Security=True"
Using MyConn = New sqlclient.SqlConnection()
Using cmd = New SqlClient.SqlCommand("EXEC CTable")
cmd.CommandType = CommandType.StoredProcedure
MyConn.Open()
cmd.ExecuteNonQuery()
End Using
End Using ' also closes the conection
Standard Security
Data Source=serverName\instanceName;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Trusted Connection
Data Source=serverName\instanceName;Initial Catalog=myDataBase;Integrated Security=SSPI;
What i'm trying to do is that from a ASP.NET (framework 4) a user shall be able to update an existing record in a SQL Database using the record Key. USING Visual Studio 2010 (vb)
I get an error of Syntax near " \ ", i have 2 textboxes:
1- For the key
2-contains the information that would be sent to the SQL server in order to update such column (Control_ClosedByRev)
Dim Con As New SqlConnection
Dim SQL As String
Dim com As SqlCommand = Con.CreateCommand
Dim KeyID As Integer
KeyID = TextBox1_UpdateDataReview.Text
Con.ConnectionString = "Data Source=WCRDUSMJEMPR9\SQLEXPRESS;Initial Catalog=MicroDB;Integrated Security=True"
Con.Open()
SQL = "UPDATE ControlCharts set Control_ClosedByRev=" & TextBox2_UpdateDataReview.Text & " where ID_ControlCharts= " & KeyID
Dim cmd As New SqlCommand(SQL, Con)
'cmd.ExecuteScalar()
cmd.ExecuteNonQuery()
Label1_UpdateDataReview.Text = "Record Updated"
i tried changing the cmd.execute, it did not work. Thanks in advance.
First off, this is quite vulnerable to SQL Injection -- read into that and use parameterized queries instead.
Here is some sample code to help.
Con.ConnectionString = "Data Source=WCRDUSMJEMPR9\\SQLEXPRESS;Initial Catalog=MicroDB;Integrated Security=True"
Con.Open()
SQL = "UPDATE ControlCharts set Control_ClosedByRev=#ClosedByRev where ID_ControlCharts=#Key"
Dim cmd As New SqlCommand(SQL, Con)
cmd.Parameters.AddWithValue("#ClosedByRev ", TextBox2_UpdateDataReview.Text)
cmd.Parameters.AddWithValue("#Key", KeyID)
cmd.ExecuteNonQuery()
Good luck.
Try this: put "#" symbol before the the string
Con.ConnectionString = #"Data Source=WCRDUSMJEMPR9\SQLEXPRESS;Initial Catalog=MicroDB;Integrated Security=True"
Or escape the slash "Data Source=WCRDUSMJEMPR9\\SQLEXPRESS;Initial Catalog=MicroDB;Integrated Security=True"
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()