c# - Connection String via IP Address For SQL Server -


i want create connection string can connect sql database remotely in c# code using oledb provider , server ip address.

note 1 : i'm using oledb because want handle different database types. sql example. note 2 : database resides on machine (machine on network)

i did setup connect machine (firewall,enable tcp/ip..etc), , can connect remotely using microsoft sql server management 2014 specifying (server name : computer name-pc\instance name) , using sql authentication entering username , password , press connect , goes well, connect successfully.

but tried lot of combinations build connection string in c# code , none of them works except :

oledbconnection conn = new oledbconnection(@"provider = sqloledb; data source = mycompname-pc\sqlexpress; initial catalog = database1 ; user id = myusername ; password = mypassword ;"); 

otherwise if try use server public ip address instead of mycompname in data source keeps giving me error : server not found or access denied.

i search in connectionstrings.com problem still there.

from post looks trying connect sql server database why using oledbconnection? instead of using sql server connection provider.

oledbconnection connection provider used connecting ms access database.

you should using sqlconnection class like

sqlconnection conn = new sqlconnection("data source = mycompname-pc\sqlexpress; initial catalog = database1 ; user id = myusername ; password = mypassword ;") 

see sqlconnection reference more information commented @alexk.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -