Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use this connection to connect to my .sdf database:
"Data Source = c:\\Database1.sdf"

but when i want to open the connection by "connection.open", it throws this exception:

"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)".

then I can't connect to the database.
for solving this problem i used:
SqlConnection with SqlCeConnection
SqlCommand with SqlCeCommand

now i will need to provide a reference to System.Data.SqlServerCe (in system.data.sqlserverce.dll)
and i donot know to how do it
please help me
Posted
Comments
[no name] 6-Sep-12 11:05am    
post your total connectionString
Ganesh Nikam 7-Sep-12 5:07am    
complete Connectionstring please

You must declare your connectionstring to the following:
http://www.connectionstrings.com/sql-server-2005-ce[^]

XML
ProviderName="System.Data.SqlServerCe.SqlCeConnection"


Hope it helps.
 
Share this answer
 
v2
First and foremost make sure that the SQL Server services are running. Other reasons could be, incorrect connection string or some Firewall blockage.

Here, have a look at this blog post to troubleshoot the issue : MSDN Blogs: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified[^]

If needed, look at these one:
Exception - error 26 - Error Locating Server Instance Specified[^]
provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance...[^]
"Specified SQL server not found" o..[^]
 
Share this answer
 
Start the SQL server service in ur service collection.(right click on the my computer,select service and applications then services,there u will get all service list. there select the SQL Server(SQLEXPRESS)service,right click and select start)
 
Share this answer
 
Why don't you use your sql server instance Name?

"server=.\{instance Name};Integrated Security=true;"
 
Share this answer
 
with this command also my problem dont solved ordercollection.counter1 is a static varaible and my code is compelete
 
Share this answer
 
i dose this but my problem dont solved
my code is compeleted and ordercollection.counter1 is a static variable
 
Share this answer
 
now my code is:
C#
class OrderMapper:Imapper
   {
       static public SqlCeConnection Qconnection = new SqlCeConnection();
       static public SqlCeCommand Qcommand = new SqlCeCommand ();
       public void put(object ob)
       {
          // Qconnection.ConnectionString = "Data Source=C:\\Users\\Admin\\Desktop\\New folder\\WindowsFormsApplication2\\WindowsFormsApplication2\\Database1.sdf";
           string str = "Data Source=|DataDirectory|\\Database1.sdf;Persist Security Info=False;";
            Qconnection.ConnectionString = str;
           Qcommand.Connection = Qconnection;
           Qconnection.Open();
           for (int i = 0; i < orderColection.counter1; i++)
           {
               string commandText = "select * from order";
              // string commandText = "INSERT INTO order VALUES(@RID,@amount,@type,@date)";
               Qcommand.CommandText = commandText;
               Qcommand.CommandType = CommandType.Text;

              /* Qcommand.Parameters.AddWithValue("@RID", orderColection.list[i].rep_id);
               Qcommand.Parameters.AddWithValue("@amount", orderColection.list[i].amount);
               Qcommand.Parameters.AddWithValue("@type", orderColection.list[i].type);
               Qcommand.Parameters.AddWithValue("@date", orderColection.list[i].date );*/
               Qcommand.ExecuteNonQuery();
           }
           Qconnection.Close();
       }
       //public object get(int oid)
      // {

       //}
   }

and my error is:


An unhandled exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll

Additional information: There was an error parsing the query. [ Token line number = 1,Token line offset = 15,Token in error = order ]
 
Share this answer
 
Comments
Matt T Heffron 6-Sep-12 15:05pm    
Isn't "select * from order" a Query? (You're calling ExecuteNonQuery.)
f.sarikhani 6-Sep-12 15:07pm    
what is correct Queryfor select all records of table ?
Matt T Heffron 6-Sep-12 18:01pm    
I think it is ExecuteReader() instead of the ExecuteNonQuery(). I'm also assuming that the "select * ..." you are executing here is just for testing, and the ExecuteNonQuery() is correct for the commented-out code. The code as shown is clearly incomplete (e.g., orderCollection is not declared anywhere, and the results of this select are never examined).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900