| | |
Create Database Connection in the C#.net
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 18
Reputation:
Solved Threads: 0
hello all,
I have database named 'Marketing', and want to bound DropDownList control with it using 'add connection' dialog box in the C#.net.
I gave datasource: 'Microsoft SQL Server Database File (SqlClient)'. And when I give DataBase file name as 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\Marketing_Data.MDF', I get error while testing the connection:
"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 default settings SQL Server dose not allow remote connections. (Provider
QL Network Interfaces, error: 26-Error Locating Server/Instance specified)".
So what DataBase File name I should give here for completing the database binding?
Thanks
I have database named 'Marketing', and want to bound DropDownList control with it using 'add connection' dialog box in the C#.net.
I gave datasource: 'Microsoft SQL Server Database File (SqlClient)'. And when I give DataBase file name as 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\Marketing_Data.MDF', I get error while testing the connection:
"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 default settings SQL Server dose not allow remote connections. (Provider
QL Network Interfaces, error: 26-Error Locating Server/Instance specified)".So what DataBase File name I should give here for completing the database binding?
Thanks
If this database resides on the server, type its name and use your suitable authentication options and select target database from databases downlist.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
What Ramy is saying is that you do not specify a File name, but rather a ConnectionString.
C# Syntax (Toggle Plain Text)
SqlConnection conn = new SqlConnection("Data Source=Servername;Initial Catalog=Marketing;Integrated Security=SSPI"); conn.Open();
Thanks Jerry
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
•
•
Join Date: Aug 2009
Posts: 1
Reputation:
Solved Threads: 0
Hi Jerry, I tried this connection but I am getting an error on "conn.Open();". Could you please help me to find out what would be the reason of this error?
following is the detail error message "Compiler Error Message: CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
"
following is the detail error message "Compiler Error Message: CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
"
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
0
#8 13 Days Ago
You don't want to keep the connection open all the time, only when you need it. As in the matter of fact, the conn.Open(); shouldn't be in your code at all. Any sql command statement such as sqlCommand and sqlDataAdapter all can take a connection as a parameter. If you have conn declared as a global variable, then you can use that variable to pass as a connection to all the sql command statements. The statement will do the connection open and closing as necessary.
![]() |
Similar Threads
- vb.net database connection (VB.NET)
- Updated : Simple ASP.Net Login Page (ASP.NET)
- How to connect sql database in asp.net using VB? (ASP.NET)
- Login and retrieve user data from database (ASP.NET)
- Registration and Login scripts using VB and Oledbconnection to Access Database (ASP.NET)
- database question (C#)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
- connecting to access via vb.net-HELP!!! (VB.NET)
Other Threads in the C# Forum
- Previous Thread: Very simple console barchart
- Next Thread: Microsoft XNA Game Studio 2.0
| Thread Tools | Search this Thread |
.net 2007 access algorithm array barchart bitmap box broadcast c# camera check checkbox client combobox control conversion cs4 csharp custom customactions database datagrid datagridview dataset date datetime degrees development draganddrop drawing encryption enum event eventcloseformc# excel file form format forms function gdi+ handler httpwebrequest image index input install java keypress label list listbox listener listview load mandelbrot math mouseclick mysql operator path photoshop picturebox pixelinversion post programming radians regex remote remoting resolved. richtextbox search security server sleep socket sql statistics stream string table text textbox thread time timer update usercontrol validation view visual visualstudio webbrowser windows winforms wordautomation wpf xml






