| | |
SQL connection fails
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2008
Posts: 42
Reputation:
Solved Threads: 1
Hi, using VB 2008 Express, I have a button on a form which is to use a datareader to loop through all the records in a file. When I try to run it I get a message indicating it could not connect. I assume something is wrong with my connection string but I don't know what. I know the path name is correct, and I know my database does not require a password. I have tried it with and without USER ID and PASSWORD. I don;t know where to look next. Any help is appreciated.
Thanks,
Bill P.
Thanks,
Bill P.
VB.NET Syntax (Toggle Plain Text)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sConnection As String = "server=(local);uid=test;pwd=PassWord;database=C:\Documents and Settings\Compaq_Owner\My Documents\Visual Studio 2008\Projects\Medications\Medications\medications.sdf" Dim objCommand As New SqlCommand objCommand.CommandText = "Select doctor From Doctors" objCommand.Connection = New SqlConnection(sConnection) objCommand.Connection.Open() Dim objDataReader As SqlDataReader = objCommand.ExecuteReader() If objDataReader.HasRows Then Do While objDataReader.Read() Console.WriteLine(" Your name is: " & objDataReader(0)) Loop Else Console.WriteLine("No rows returned.") End If objDataReader.Close() objCommand.Dispose() End Sub End Class
•
•
Join Date: Jul 2008
Posts: 42
Reputation:
Solved Threads: 1
I find my connection string saved in my application configuration file, but when I refer to it by name I get this error message:
Error 1 Reference to a non-shared member requires an object reference.
Here is the app.config entry:
Thanks,
Bill P.
Error 1 Reference to a non-shared member requires an object reference.
Here is the app.config entry:
VB.NET Syntax (Toggle Plain Text)
<connectionStrings> <add name="WindowsApplication1.My.MySettings.medicationsConnectionString" connectionString="Data Source=|DataDirectory|\medications.sdf" providerName="Microsoft.SqlServerCe.Client.3.5" /> </connectionStrings>
Bill P.
The problem is your connection string. To connect to a SQL server Compact edition database you use the following:
Here you get more info about how to use the App.config information in your application
VB.NET Syntax (Toggle Plain Text)
Data Source=MyData.sdf;Persist Security Info=False;
•
•
•
•
How to specify the location of the SDF file
Often times the .SDF database is not running in the current directory so it becomes necessary to programatically set the path to the SDF file. This is an example (.net C#) on how to do this when the SDF file is located in the same directory as the executing application.
VB.NET Syntax (Toggle Plain Text)
Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\MyData.sdf;Persist Security Info=False;
Here you get more info about how to use the App.config information in your application
Last edited by ChaseVoid; Jul 21st, 2008 at 1:51 pm. Reason: Added website : http://www.codeguru.com/columns/DotNet/article.php/c7987/
•
•
Join Date: Jul 2008
Posts: 42
Reputation:
Solved Threads: 1
When I use
I get error:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
VB.NET Syntax (Toggle Plain Text)
Data Source=MyData.sdf;Persist Security Info=False;Data Source=MyData.sdf;Persist Security Info=False;
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
•
•
Join Date: Jul 2008
Posts: 42
Reputation:
Solved Threads: 1
SQL Server Browser was stopped. I started it. Now I get:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
![]() |
Similar Threads
- Apache (Linux Servers and Apache)
- SQL AddWithValue problems (VB.NET)
- help with sql d/base & java gui (Java)
- MSSQL connection strings (MS SQL)
- Terrible Error while using MySQL resources (PHP)
Other Threads in the VB.NET Forum
- Previous Thread: Errorhandler vs. Msgbox for errors - preference?
- Next Thread: Graph controls
Views: 3021 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2005 2008 access account application array arrays basic bing button buttons c# center check checkbox code convert crystalreport data database datagrid datagridview date design designer dissertation dissertations dropdownlist excel fade file-dialog filter ftp generatetags google gridview hardcopy images inline input insert installer intel internet listview mobile monitor net networking objects output panel passingparameters picturebox port position print printing problem read remove save searchbox searchvb.net select serial shutdown soap sorting studio survey table tcp temperature text textbox time timer timespan toolbox trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet visual visualbasic visualbasic.net visualstudio2008 web webbrowser winforms wpf year





